<!DOCTYPE html>
<!-- saved from url=(0038)https://www.jianshu.com/p/486b0965c296 -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1"><meta http-equiv="Cache-Control" content="no-siteapp"><meta http-equiv="Cache-Control" content="no-transform"><meta name="applicable-device" content="pc,mobile"><meta name="MobileOptimized" content="width"><meta name="HandheldFriendly" content="true"><meta name="theme-color" content="#ec7259"><meta name="renderer" content="webkit"><meta name="force-rendering" content="webkit"><meta name="google" value="notranslate"><meta property="wb:webmaster" content="294ec9de89e7fadb"><meta property="qc:admins" content="104102651453316562112116375"><meta property="qc:admins" content="11635613706305617"><meta property="qc:admins" content="1163561616621163056375"><meta name="360-site-verification" content="604a14b53c6b871206001285921e81d8"><meta name="google-site-verification" content="cV4-qkUJZR6gmFeajx_UyPe47GW9vY6cnCrYtCHYNh4"><meta name="google-site-verification" content="HF7lfF8YEGs1qtCE-kPml8Z469e2RHhGajy6JPVy5XI"><meta name="tencent-site-verification" content="da26ce22cfed7aba6a96d8409f9b53a6"><meta name="apple-mobile-web-app-title" content="简书"><link href="" rel="shortcut icon" type="image/x-icon"><link rel="dns-prefetch" href="https://cdn2.jianshu.io/"><link rel="dns-prefetch" href="https://upload-images.jianshu.io/"><meta name="referrer" content="always"><meta http-equiv="mobile-agent" content="format=html5; url=http://maleskine-production:30000/p/486b0965c296"><meta name="apple-itunes-app" content="app-id=888237539, app-argument=jianshu://notes/4008134"><meta property="al:ios:url" content="jianshu://notes/4008134"><meta property="al:ios:app_store_id" content="888237539"><meta property="al:ios:app_name" content="简书"><meta property="al:android:url" content="jianshu://notes/4008134"><meta property="al:android:package" content="com.jianshu.haruki"><meta property="al:android:app_name" content="简书"><title>聊聊Linux 五种IO模型 - 简书</title><meta name="robots" content="index,follow"><meta name="googlebot" content="index,follow"><meta name="description" content="上一篇《聊聊同步、异步、阻塞与非阻塞》[https://www.jianshu.com/p/aed6067eeac9]已经通俗的讲解了，要理解同步、异步、阻塞与非阻塞重要的两..."><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@jianshu.com"><meta property="fb:app_id" content="865829053512461"><meta property="og:url" content="http://maleskine-production:30000/p/486b0965c296"><meta property="og:type" content="article"><meta property="og:title" content="聊聊Linux 五种IO模型"><meta property="og:description" content="上一篇《聊聊同步、异步、阻塞与非阻塞》[https://www.jianshu.com/p/aed6067eeac9]已经通俗的讲解了，要理解同步、异步、阻塞与非阻塞重要的两..."><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png"><meta property="og:site_name" content="简书"><script type="text/javascript" src="聊聊Linux%20五种IO模型%20-%20简书_files/z_stat.php"></script><meta name="next-head-count" content="47"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/[slug].js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/_app.js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/webpack-b1da0f857c45af7b8400.js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/commons.a44ef645208dcbc051d0.js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/styles.d2e8d5d9794ce93096fa.js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/main-bf58e64b3bbaeed6553f.js.下载" as="script"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/commons.90b98cc2.chunk.css" as="style"><link rel="stylesheet" href="./聊聊Linux 五种IO模型 - 简书_files/commons.90b98cc2.chunk.css"><link rel="preload" href="./聊聊Linux 五种IO模型 - 简书_files/styles.13ba09e6.chunk.css" as="style"><link rel="stylesheet" href="./聊聊Linux 五种IO模型 - 简书_files/styles.13ba09e6.chunk.css"><link rel="stylesheet" type="text/css" href="./聊聊Linux 五种IO模型 - 简书_files/12.a0f2aca1.chunk.css"><script charset="utf-8" src="聊聊Linux%20五种IO模型%20-%20简书_files/12.2a728188df0ce5223331.js.下载"></script><link rel="stylesheet" type="text/css" href="./聊聊Linux 五种IO模型 - 简书_files/13.66abcb05.chunk.css"><script charset="utf-8" src="聊聊Linux%20五种IO模型%20-%20简书_files/13.652a67760a8cf980b66a.js.下载"></script><script charset="utf-8" src="聊聊Linux%20五种IO模型%20-%20简书_files/11.75b56346ed2db2849ee4.js.下载"></script></head><body class="reader-night-mode" style=""><svg class="wCYvWN" style="display:none;width:0;height:0" width="0" height="0" focusable="false" aria-hidden="true"><symbol id="ic-icon_requests" viewBox="0 0 1024 1024"><path d="M934.4 627.2A38.4 38.4 0 0 1 972.8 665.6v128a140.8 140.8 0 0 1-140.8 140.8H192A140.8 140.8 0 0 1 51.2 793.6V665.6a38.4 38.4 0 1 1 76.8 0v128c0 35.328 28.672 64 64 64h640c35.328 0 64-28.672 64-64V665.6a38.4 38.4 0 0 1 38.4-38.4zM587.4688 91.392l281.8048 244.224a64 64 0 0 1-41.8816 112.384h-148.992V665.6a89.6 89.6 0 0 1-89.6 89.6h-153.6A89.6 89.6 0 0 1 345.6 665.6V448H196.608a64 64 0 0 1-41.8816-112.384l281.8048-244.224a115.2 115.2 0 0 1 150.9376 0zM486.8608 149.4016L230.912 371.2H384a38.4 38.4 0 0 1 38.4 38.4v256c0 7.0656 5.7344 12.8 12.8 12.8h153.6a12.8 12.8 0 0 0 12.8-12.8V409.6a38.4 38.4 0 0 1 38.4-38.4h153.088L537.088 149.4016a38.4 38.4 0 0 0-50.2784 0z"></path></symbol><symbol id="ic-icon_others" viewBox="0 0 1024 1024"><path d="M512 435.2a76.8 76.8 0 1 1 0 153.6 76.8 76.8 0 0 1 0-153.6z m-307.2 0a76.8 76.8 0 1 1 0 153.6 76.8 76.8 0 0 1 0-153.6z m614.4 0a76.8 76.8 0 1 1 0 153.6 76.8 76.8 0 0 1 0-153.6z"></path></symbol><symbol id="ic-icon_money" viewBox="0 0 1024 1024"><path d="M512 51.2a460.8 460.8 0 1 1 0 921.6 460.8 460.8 0 0 1 0-921.6z m0 76.8a384 384 0 1 0 0 768 384 384 0 0 0 0-768zM435.0976 311.3984L510.1568 450.56l75.264-139.52a37.7344 37.7344 0 0 1 49.664-16.0256 33.9456 33.9456 0 0 1 14.7968 47.104l-76.288 135.7824h102.4a29.0304 29.0304 0 1 1 0 58.0608h-127.0272v55.0912h126.976a29.0304 29.0304 0 1 1 0 58.0608h-126.976v49.152a38.8096 38.8096 0 1 1-77.6192 0v-49.152H345.2416a29.0304 29.0304 0 1 1 0-58.0608h126.1056v-55.0912H345.2416a29.0304 29.0304 0 0 1 0-58.0608h101.4272L369.0496 342.784a34.304 34.304 0 0 1 15.0016-48.0768 38.9632 38.9632 0 0 1 51.0464 16.6912z"></path></symbol><symbol id="ic-icon_follows" viewBox="0 0 1024 1024"><path d="M844.8 614.4a38.4 38.4 0 0 1 38.4 38.4v102.4h102.4a38.4 38.4 0 1 1 0 76.8h-102.4512l0.0512 102.4a38.4 38.4 0 1 1-76.8 0l-0.0512-102.4H704a38.4 38.4 0 1 1 0-76.8h102.4v-102.4a38.4 38.4 0 0 1 38.4-38.4z m-370.176-89.6c80.5888 0 158.3104 16.896 227.4816 48.64a38.4 38.4 0 1 1-32.0512 69.7856 468.2752 468.2752 0 0 0-195.3792-41.6256c-175.616 0-327.7312 93.184-378.112 223.9488-13.4144 38.5536-4.7616 57.5488 7.8336 57.5488H665.6a38.4 38.4 0 1 1 0 76.8H104.448c-74.24 0-109.1584-76.8-80.0256-160.768 62.8736-163.1232 244.3264-274.3296 450.2528-274.3296zM460.8 12.8a243.2 243.2 0 1 1 0 486.4 243.2 243.2 0 0 1 0-486.4z m0 76.8a166.4 166.4 0 1 0 0 332.8 166.4 166.4 0 0 0 0-332.8z"></path></symbol><symbol id="ic-icon_comments" viewBox="0 0 1024 1024"><path d="M537.6 51.2a435.2 435.2 0 1 1 0 870.4h-51.2a433.2544 433.2544 0 0 1-209.2544-53.504l-126.976 94.8224a51.2 51.2 0 0 1-81.8688-41.0624v-314.2144A435.2 435.2 0 0 1 486.4 51.2h51.2z m0 76.8h-51.2a358.4 358.4 0 0 0-344.32 458.24c2.048 6.9632 3.072 14.1824 3.072 21.4016v263.168l86.016-64.256a76.8 76.8 0 0 1 82.944-5.7856c52.3264 28.7744 111.104 44.032 172.288 44.032h51.2a358.4 358.4 0 0 0 0-716.8z m89.6 435.2a38.4 38.4 0 1 1 0 76.8h-230.4a38.4 38.4 0 1 1 0-76.8h230.4z m0-204.8a38.4 38.4 0 1 1 0 76.8h-230.4a38.4 38.4 0 0 1 0-76.8h230.4z"></path></symbol><symbol id="ic-icon_chat" viewBox="0 0 1024 1024"><path d="M870.4 153.6a102.4 102.4 0 0 1 102.4 102.4v512a102.4 102.4 0 0 1-102.4 102.4H153.6a102.4 102.4 0 0 1-102.4-102.4V256a102.4 102.4 0 0 1 102.4-102.4h716.8z m0 76.8H153.6a25.6 25.6 0 0 0-25.6 25.6v512a25.6 25.6 0 0 0 25.6 25.6h716.8a25.6 25.6 0 0 0 25.6-25.6V256a25.6 25.6 0 0 0-25.6-25.6z m-113.7664 97.3312a38.4 38.4 0 0 1 47.1552 60.5696l-274.5856 213.9136a38.4 38.4 0 0 1-47.2064 0L208.384 389.12a38.4 38.4 0 1 1 47.2064-60.6208l250.0096 194.7648z"></path></symbol><symbol id="ic-icon_collection" viewBox="0 0 1024 1024"><path d="M819.2 51.2a102.4 102.4 0 0 1 102.4 102.4v707.6864a76.8 76.8 0 0 1-104.192 71.7824L512 816.4864l-305.408 116.5824A76.8 76.8 0 0 1 102.4 861.2864V153.6a102.4 102.4 0 0 1 102.4-102.4h614.4z m0 76.8H204.8a25.6 25.6 0 0 0-25.6 25.6v707.6864l305.408-116.5312a76.8 76.8 0 0 1 54.784 0l305.408 116.5312V153.6a25.6 25.6 0 0 0-25.6-25.6z m-293.6832 105.984a25.6 25.6 0 0 1 8.192 8.192l63.744 102.2464 116.9408 28.9792a25.6 25.6 0 0 1 13.4144 41.3184L650.24 506.9312l8.5504 120.1664a25.6 25.6 0 0 1-35.1232 25.5488L512 607.3856l-111.616 45.2608a25.6 25.6 0 0 1-35.1744-25.5488L373.76 506.9312l-77.568-92.16a25.6 25.6 0 0 1 13.4144-41.3696l116.9408-28.9792L490.2912 242.176a25.6 25.6 0 0 1 35.2256-8.192zM512 352.512l-20.2752 32.512a76.8 76.8 0 0 1-46.6944 33.9456l-37.1712 9.216 24.6784 29.2864a76.8 76.8 0 0 1 17.8176 54.9376l-2.7136 38.1952 35.4816-14.3872a76.8 76.8 0 0 1 57.7536 0l35.4816 14.336-2.7136-38.144a76.8 76.8 0 0 1 17.8176-54.9376l24.6784-29.2864-37.1712-9.216a76.8 76.8 0 0 1-46.6944-33.9456L512 352.512z"></path></symbol><symbol id="ic-icon_help" viewBox="0 0 1024 1024"><path d="M512 51.2a460.8 460.8 0 1 1 0 921.6 460.8 460.8 0 0 1 0-921.6z m0 76.8a384 384 0 1 0 0 768 384 384 0 0 0 0-768zM512 716.8a51.2 51.2 0 1 1 0 102.4 51.2 51.2 0 0 1 0-102.4z m0-481.8944a166.4 166.4 0 0 1 166.4 166.4c0 46.848-26.7264 78.336-79.8208 116.992l-23.552 16.7936a299.008 299.008 0 0 0-18.0736 13.7216c-4.9664 4.1984-6.4 5.9392-6.5536 2.2528v89.088a38.4 38.4 0 1 1-76.8 0V547.84c0.512-23.1936 12.7488-39.936 33.9456-57.7536 6.2464-5.2736 13.1584-10.496 22.7328-17.408 1.2288-0.8704 18.2272-12.9024 23.1424-16.4864 33.9968-24.7296 48.1792-41.472 48.1792-54.8864a89.6 89.6 0 0 0-179.2 0 38.4 38.4 0 0 1-76.8 0A166.4 166.4 0 0 1 512 234.9056z"></path></symbol><symbol id="ic-icon_like" viewBox="0 0 1024 1024"><path d="M921.344 180.5312a269.3632 269.3632 0 0 1 0 377.2928l-372.8896 378.0096a51.2 51.2 0 0 1-72.9088 0l-372.8896-378.0096a269.3632 269.3632 0 0 1 0-377.2928 260.608 260.608 0 0 1 372.1216 0l37.2224 37.7344 37.2224-37.7344a260.608 260.608 0 0 1 372.1216 0zM157.3376 234.496a192.5632 192.5632 0 0 0 0 269.4144L512 863.4368l354.6624-359.5776a192.5632 192.5632 0 0 0 0-269.4144 183.808 183.808 0 0 0-262.7584 0L515.4304 324.096 400.128 443.5968a38.4 38.4 0 0 1-55.2448-53.3504L458.0864 272.896l-37.9904-38.5024a183.808 183.808 0 0 0-262.7584 0z"></path></symbol><symbol id="ic-icon_purchased" viewBox="0 0 1024 1024"><path d="M819.2 51.2a102.4 102.4 0 0 1 102.4 102.4v716.8a102.4 102.4 0 0 1-102.4 102.4H204.8a102.4 102.4 0 0 1-102.4-102.4V153.6a102.4 102.4 0 0 1 102.4-102.4h614.4z m0 76.8H204.8a25.6 25.6 0 0 0-25.6 25.6v716.8a25.6 25.6 0 0 0 25.6 25.6h614.4a25.6 25.6 0 0 0 25.6-25.6V153.6a25.6 25.6 0 0 0-25.6-25.6z m-67.1744 341.0944a38.4 38.4 0 0 1 10.3424 53.3504l-186.112 275.8656a38.4 38.4 0 0 1-53.2992 10.3936l-148.5824-100.1984a38.4 38.4 0 1 1 43.008-63.6928l116.736 78.7456 164.5568-244.0704a38.4 38.4 0 0 1 53.3504-10.3936zM473.6 435.2a38.4 38.4 0 0 1 0 76.8h-179.2a38.4 38.4 0 0 1 0-76.8h179.2z m102.4-179.2a38.4 38.4 0 1 1 0 76.8h-281.6a38.4 38.4 0 0 1 0-76.8h281.6z"></path></symbol><symbol id="ic-icon_logout" viewBox="0 0 1024 1024"><path d="M832 64c70.8096 0 128 58.0608 128 129.4336v45.5168a38.4 38.4 0 1 1-76.8 0v-45.568c0-29.184-23.04-52.5824-51.2-52.5824H243.2c-28.16 0-51.2 23.4496-51.2 52.6336v637.1328c0 29.184 23.04 52.6336 51.2 52.6336h588.8c28.16 0 51.2-23.4496 51.2-52.6336v-45.5168a38.4 38.4 0 0 1 76.8 0v45.568c0 71.3216-57.1904 129.3824-128 129.3824H243.2c-70.8096 0-128-58.0608-128-129.4336V193.4336c0-71.3728 57.1904-129.4336 128-129.4336z m-52.6336 248.064l160.8192 160.8192a38.4 38.4 0 0 1 2.1504 56.32l-162.9184 162.9184a38.4 38.4 0 0 1-54.272-54.272l97.3312-97.3824h-413.696c-13.9264 0-25.4464-14.2336-27.392-32.768l-0.3072-5.632c0-19.3024 10.24-35.2768 23.552-37.9904l4.096-0.4608 413.6448 0.0512-97.28-97.28a38.4 38.4 0 0 1 54.272-54.3232z"></path></symbol><symbol id="ic-icon_wallet" viewBox="0 0 1024 1024"><path d="M870.4 128a102.4 102.4 0 0 1 102.4 102.4v563.2a102.4 102.4 0 0 1-102.4 102.4H153.6a102.4 102.4 0 0 1-102.4-102.4v-563.2a102.4 102.4 0 0 1 102.4-102.4h716.8zM870.4 204.8H153.6a25.6 25.6 0 0 0-25.6 25.6V307.2H358.4a204.8 204.8 0 1 1 0 409.6H128v76.8a25.6 25.6 0 0 0 25.6 25.6h716.8a25.6 25.6 0 0 0 25.6-25.6v-563.2A25.6 25.6 0 0 0 870.4 204.8zM358.4 384H128v256H358.4a128 128 0 1 0 0-256z m-25.6 51.2a76.8 76.8 0 1 1 0 153.6 76.8 76.8 0 0 1 0-153.6z"></path></symbol><symbol id="ic-icon_mine" viewBox="0 0 1024 1024"><path d="M512.3072 549.4272h6.5024-7.168a588.0832 588.0832 0 0 1 28.16 0.6144l6.3488 0.4096c3.6352 0.1536 7.2704 0.4096 10.9056 0.6656l4.864 0.512c62.8736 5.2224 123.2384 20.6336 178.176 45.1584 1.536 0.7168 3.072 1.536 4.608 2.4064l1.8944 0.8704c100.352 46.6432 178.8416 122.6752 215.9616 216.32 29.184 81.664-5.8368 156.416-80.128 156.416l-178.176-0.0512-0.768 0.0512H141.568C67.328 972.8 32.256 898.048 61.44 816.384c37.12-93.6448 115.5584-169.6768 215.9616-216.32l1.9456-0.8704a39.168 39.168 0 0 1 4.608-2.4064c54.8864-24.576 115.2512-39.936 178.1248-45.2608l4.864-0.3584c3.584-0.3072 7.2704-0.5632 10.9056-0.768l6.3488-0.3072a671.5904 671.5904 0 0 1 28.1088-0.6656h-7.1168 6.5024z m370.176 348.672c12.5952 0 21.248-18.4832 7.8336-56.0128-47.0528-118.6304-182.7328-205.568-343.4496-216.7296a229.9392 229.9392 0 0 0-7.9872-0.512l7.9872 0.512a507.6992 507.6992 0 0 0-69.7344 0l7.9872-0.512c-164.1984 8.8576-303.616 96.6144-351.4368 217.2416-13.4144 37.5296-4.7616 55.9616 7.8848 55.9616h740.864zM498.3808 51.2c134.5024 0 243.5584 105.984 243.5584 236.6464 0 130.7136-109.056 236.6464-243.5584 236.6464S254.8736 418.56 254.8736 287.8464 363.9296 51.2 498.432 51.2z m0 74.752c-92.0064 0-166.656 72.4992-166.656 161.8944 0 89.4464 74.6496 161.9456 166.656 161.9456s166.6048-72.4992 166.6048-161.9456c0-89.3952-74.5984-161.8944-166.6048-161.8944z"></path></symbol><symbol id="ic-icon_setting" viewBox="0 0 1024 1024"><path d="M708.864 68.608a102.4 102.4 0 0 1 88.6784 51.2L994.4576 460.8a102.4 102.4 0 0 1 0 102.4l-196.9152 340.992a102.4 102.4 0 0 1-88.6784 51.2h-393.728a102.4 102.4 0 0 1-88.6784-51.2L29.5424 563.2a102.4 102.4 0 0 1 0-102.4l196.9152-340.992a102.4 102.4 0 0 1 88.6784-51.2h393.728z m0 76.8h-393.728a25.6 25.6 0 0 0-22.1696 12.8L96.0512 499.2a25.6 25.6 0 0 0 0 25.6l196.9152 340.992a25.6 25.6 0 0 0 22.1696 12.8h393.728a25.6 25.6 0 0 0 22.1696-12.8l196.9152-340.992a25.6 25.6 0 0 0 0-25.6l-196.9152-340.992a25.6 25.6 0 0 0-22.1696-12.8zM512 345.6a166.4 166.4 0 1 1 0 332.8 166.4 166.4 0 0 1 0-332.8z m0 76.8a89.6 89.6 0 1 0 0 179.2 89.6 89.6 0 0 0 0-179.2z"></path></symbol><symbol id="ic-spinner" viewBox="0 0 1024 1024"><path d="M300.571429 817.90476233q0 30.285714-21.428572 51.714285T227.428571 891.04761933q-29.714286 0-51.428571-21.714286t-21.714286-51.428571q0-30.285714 21.428572-51.714286T227.428571 744.76190433t51.714286 21.428572T300.571429 817.90476233z m284.571428 117.714285q0 30.285714-21.428571 51.714286T512 1008.76190433t-51.714286-21.428571T438.857143 935.61904733t21.428571-51.714285T512 862.47619033t51.714286 21.428572 21.428571 51.714285zM182.857143 533.33333333q0 30.285714-21.428572 51.714286T109.714286 606.47619033t-51.714286-21.428571T36.571429 533.33333333t21.428571-51.714286T109.714286 460.19047633t51.714285 21.428571T182.857143 533.33333333z m686.857143 284.571429q0 29.714286-21.714286 51.428571t-51.428571 21.714286q-30.285714 0-51.714286-21.428572T723.428571 817.90476233t21.428572-51.714286 51.714286-21.428572 51.714285 21.428572 21.428572 51.714286zM318.857143 248.76190433q0 37.714286-26.857143 64.571429t-64.571429 26.857143-64.571428-26.857143-26.857143-64.571429 26.857143-64.571428 64.571428-26.857143 64.571429 26.857143 26.857143 64.571428z m668.571428 284.571429q0 30.285714-21.428571 51.714286T914.285714 606.47619033t-51.714285-21.428571T841.142857 533.33333333t21.428572-51.714286T914.285714 460.19047633t51.714286 21.428571T987.428571 533.33333333z m-365.714285-402.285714q0 45.714286-32 77.714285t-77.714286 32-77.714286-32-32-77.714285 32-77.714286T512 21.33333333t77.714286 32 32 77.714286z m302.857143 117.714285q0 53.142857-37.714286 90.571429T796.571429 376.76190433q-53.142857 0-90.571429-37.428571T668.571429 248.76190433q0-52.571429 37.428571-90.285714t90.571429-37.714286q52.571429 0 90.285714 37.714286t37.714286 90.285714z"></path></symbol><symbol id="ic-alipay" viewBox="0 0 1024 1024"><path d="M1023.795 853.64v6.348a163.807 163.807 0 0 1-163.807 163.807h-696.18A163.807 163.807 0 0 1 0 859.988v-696.18A163.807 163.807 0 0 1 163.807 0h696.181a163.807 163.807 0 0 1 163.807 163.807V853.64z" fill="#009FE9"></path><path d="M844.836 648.267c-40.952-14.333-95.623-34.809-156.846-57.128a949.058 949.058 0 0 0 90.094-222.573H573.325V307.14h245.711v-43.41l-245.71 2.458V143.33H472.173c-18.223 0-21.704 20.476-21.704 20.476v102.38H204.759v40.952h245.71v61.427H245.712v40.952h409.518a805.522 805.522 0 0 1-64.909 148.246c-128.384-42.795-266.186-77.604-354.233-55.08a213.564 213.564 0 0 0-112.003 63.27c-95.418 116.917-26.21 294.034 175.274 294.034 119.989 0 236.087-67.366 325.771-177.73 134.322 65.932 398.666 176.297 398.666 176.297V701.3s-32.352-4.095-178.96-53.033z m-563.702 144.97c-158.893 0-204.759-124.699-126.336-194.112a191.86 191.86 0 0 1 90.913-46.276c93.575-10.238 189.811 35.629 293.624 86.614-74.941 94.598-166.674 153.774-258.2 153.774z" fill="#FFFFFF"></path></symbol><symbol id="ic-wechat-pay" viewBox="0 0 1076 1024"><path d="M410.493712 644.226288c-64.448471 36.97706-74.006881-20.759958-74.006881-20.759958l-80.772173-193.983933c-31.078562-92.178305 26.897497-41.56191 26.897498-41.561909s49.746372 38.732181 87.50193 62.333712c37.732946 23.602608 80.745253 6.927882 80.745254 6.927882l528.043743-250.842313C881.479874 81.578667 720.547129 0 538.352656 0 241.013636 0 0 217.098768 0 484.919453c0 154.046856 79.806318 291.154103 204.11518 380.019214L181.698086 997.56551s-10.92805 38.720336 26.945952 20.759958c25.808892-12.243853 91.603314-56.122953 130.768353-82.82771 61.570288 22.083298 128.651441 34.345455 198.970414 34.345455 297.315331 0 538.378498-217.098768 538.378499-484.924837 0-77.573115-20.313102-150.8338-56.295235-215.861568-168.236416 104.176656-559.545472 346.282128-609.973434 375.167327z" fill="#00cc22"></path></symbol><symbol id="ic-emoji" viewBox="0 0 1024 1024"><path d="M32 512C32 246.90332 246.90332 32 512 32 777.09668 32 992 246.90332 992 512 992 777.09668 777.09668 992 512 992 246.90332 992 32 777.09668 32 512ZM920 512C920 286.66782219 737.33217875 104 512 104 286.66782219 104 104 286.66782219 104 512 104 737.33217875 286.66782219 920 512 920 737.33217875 920 920 737.33217875 920 512ZM667.59732781 584C661.80988156 664.88360937 594.35802594 728.70452469 512 728.70452469 429.64197219 728.70452469 362.19011938 664.88360937 356.40267313 584 401.27447563 599.63467063 454.6818125 608.70452469 512 608.70452469 569.3181875 608.70452469 622.72552156 599.63467063 667.59732781 584L667.59732781 584ZM368 440C394.50966781 440 416 418.50966781 416 392 416 365.49033219 394.50966781 344 368 344 341.49033219 344 320 365.49033219 320 392 320 418.50966781 341.49033219 440 368 440ZM656 440C682.50966594 440 704 418.50966781 704 392 704 365.49033219 682.50966594 344 656 344 629.49033406 344 608 365.49033219 608 392 608 418.50966781 629.49033406 440 656 440Z"></path></symbol><symbol id="ic-dislike" viewBox="0 0 1137 1024"><path d="M771.413333 668.728889c-18.773333 3.015111-25.031111 20.878222-28.16 29.866667v217.884444c0 59.733333-49.948444 107.52-112.412444 107.52a115.427556 115.427556 0 0 1-112.412445-92.558222c-31.857778-190.919111-146.830222-263.850667-230.627555-290.133334a27.420444 27.420444 0 0 1-19.228445-26.168888V37.944889C268.572444 17.066667 285.582222 0 306.631111 0h567.864889c59.335111 11.946667 99.953778 32.824889 128 89.543111l128.113778 429.909333c24.974222 77.653333-15.644444 152.291556-106.211556 149.276445H771.413333z m-605.866666-32.824889H81.180444C37.546667 635.904 0 600.064 0 558.250667V80.611556C0 35.84 34.360889 0 81.180444 0H165.546667c29.297778 0 53.077333 23.779556 53.077333 53.077333v529.749334a53.077333 53.077333 0 0 1-53.077333 53.077333z"></path></symbol><symbol id="ic-close" viewBox="0 0 1024 1024"><path d="M511.99967832 371.66626953L792.60221182 91.06373692a99.19122714 99.19122714 0 0 1 140.33340878 140.33340878L652.33308711 511.99967832l280.60253349 280.6025335a99.19122714 99.19122714 0 1 1-140.33340878 140.33340878L511.99967832 652.33308711l-280.60253262 280.60253349a99.19122714 99.19122714 0 1 1-140.33340878-140.33340878L371.66626953 511.99967832 91.06373692 231.3971457A99.19122714 99.19122714 0 1 1 231.3971457 91.06373692L511.99967832 371.66626953z"></path></symbol><symbol id="ic-right" viewBox="0 0 1024 1024"><path d="M570.461091 506.693818L241.384727 177.524364A93.090909 93.090909 0 1 1 373.015273 45.893818L768 440.878545a93.090909 93.090909 0 0 1 0 131.630546l-394.984727 394.891636A93.090909 93.090909 0 0 1 241.384727 835.770182l329.076364-329.076364z"></path></symbol><symbol id="ic-more" viewBox="0 0 4096 1024"><path d="M3495.04988446 991.9952a481.91759063 481.91759063 0 0 1-483.83758031-479.9976c0-265.19867437 216.71891625-479.9976 483.83758031-479.9976S3978.64746665 246.79892562 3978.64746665 511.9976c0 264.95867531-216.47891719 479.9976-483.59758219 479.9976M2065.61703196 991.9952a481.91759063 481.91759063 0 0 1-483.35758312-479.9976c0-265.19867437 216.47891719-479.9976 483.35758312-479.9976 267.11866406 0 483.59758219 214.79892563 483.59758219 479.9976 0 264.95867531-216.47891719 479.9976-483.59758219 479.9976M622.26424884 991.9952A481.91759063 481.91759063 0 0 1 138.66666665 511.9976C138.66666665 246.79892562 355.14558384 32 622.26424884 32S1105.86183102 246.79892562 1105.86183102 511.9976c0 264.95867531-216.47891719 479.9976-483.59758218 479.9976"></path></symbol><symbol id="ic-toggle" viewBox="0 0 1024 1024"><path d="M350.366755 1023.926863a50.025855 50.025855 0 0 0 50.025855-50.025855V174.803795a73.137215 73.137215 0 0 0-124.47954-52.146834L36.096141 359.109577a50.830365 50.830365 0 0 0-0.731372 71.674471 50.537816 50.537816 0 0 0 71.601334 0.877647l193.301659-189.425388v731.737838c0 27.645867 22.453125 50.025855 50.025855 50.025855z"></path><path d="M720.953024 0.005851a47.246641 47.246641 0 0 0-47.246641 47.246641v799.389761a73.137215 73.137215 0 0 0 124.9915 51.634874l190.522446-191.619503a51.415462 51.415462 0 0 0 1.31647-71.089374 45.783897 45.783897 0 0 0-67.066827-0.292548l-155.343445 165.802066V47.252492A47.246641 47.246641 0 0 0 720.953024 0.005851z"></path></symbol><symbol id="ic-notebook" viewBox="0 0 1024 1024"><path d="M178.390055 120.591045C111.268624 120.591045 56.888889 174.401955 56.888889 240.556383V903.97778C56.888889 970.302855 111.097977 1024 178.390055 1024h545.731364c67.121431 0 121.558049-53.81091 121.558049-120.02222V240.613265c0-66.268192-54.209088-120.02222-121.558049-120.02222H178.390055z m455.117432 301.136319H269.06087a30.147761 30.147761 0 0 1 0-60.238641h364.503499a30.147761 30.147761 0 0 1 0 60.238641z m303.18409 301.136318a30.318409 30.318409 0 0 1-30.375291-30.318409V180.317742c0-66.268192-53.81091-120.02222-121.330519-120.022219H329.697688a30.147761 30.147761 0 0 1 0-60.23864l454.946784 0.056882C885.326618 0.113765 967.009987 80.887013 967.009987 180.602155v511.943118a30.318409 30.318409 0 0 1-30.31841 30.318409z m-303.18409-120.47728H269.06087a30.147761 30.147761 0 1 1 0-60.238641h364.503499a30.147761 30.147761 0 0 1 0 60.238641z"></path></symbol><symbol id="ic-check" viewBox="0 0 1433 1024"><path d="M586.88355555 719.072L1197.82755555 108.128a96 96 0 0 1 135.744 135.744L654.75555555 922.688a96 96 0 0 1-135.744 0L111.68355555 515.456A96 96 0 0 1 247.42755555 379.52l339.456 339.456z"></path></symbol><symbol id="ic-plus" viewBox="0 0 1024 1024"><path d="M437.00000029 437.00000029V136.99999971a74.99999971 74.99999971 0 1 1 149.99999942 0v300.00000058h300.00000058a74.99999971 74.99999971 0 0 1 0 149.99999942H586.99999971v300.00000058a74.99999971 74.99999971 0 0 1-149.99999942 0V586.99999971H136.99999971a74.99999971 74.99999971 0 1 1 0-149.99999942h300.00000058z"></path></symbol><symbol id="ic-pencil" viewBox="0 0 1092 1024"><path d="M597.469867 198.724267L81.92 718.574933 0 1024l309.4528-74.410667 512-521.762133-223.982933-229.102933z m400.861866-37.888L858.5216 17.885867a58.845867 58.845867 0 0 0-84.309333 0L657.2032 137.6256l223.914667 229.1712 117.1456-119.808a61.576533 61.576533 0 0 0 0-86.152533h0.068266zM546.133333 930.884267h546.133334V1024H546.133333v-93.115733z m273.066667-186.1632h273.066667v93.115733h-273.066667v-93.115733z"></path></symbol><symbol id="ic-sugar" viewBox="0 0 1024 1024"><path d="M562.362182 689.338182L352.581818 422.632727a182.737455 182.737455 0 0 1 109.056-85.876363l209.780364 266.612363a182.737455 182.737455 0 0 1-109.056 85.876364z m-28.811637 5.725091a183.296 183.296 0 0 1-193.349818-245.76l193.349818 245.76z m150.248728-118.225455l-193.349818-245.76a183.249455 183.249455 0 0 1 193.349818 245.76zM558.545455 282.065455l-40.215273-150.109091 151.738182-40.680728-13.544728-50.548363-202.333091 54.178909L503.156364 277.550545a235.659636 235.659636 0 0 0-199.493819 345.553455L120.925091 672.069818l13.544727 50.548364 200.704-53.76A236.683636 236.683636 0 0 0 465.454545 744.075636l40.215273 150.155637-151.738182 40.634182 13.544728 50.594909 202.333091-54.225455-48.965819-182.690909a235.613091 235.613091 0 0 0 199.493819-345.553455l182.690909-48.919272-13.544728-50.594909-200.704 53.76A236.683636 236.683636 0 0 0 558.545455 282.065455z m126.882909-32.256l126.464-33.885091-13.544728-50.594909-101.189818 27.136-27.089454-101.189819-50.594909 13.544728 40.680727 151.738181 25.274182-6.74909zM338.618182 776.378182l-126.464 33.885091 13.544727 50.548363 101.189818-27.089454 27.089455 101.143273 50.594909-13.498182-40.680727-151.738182-25.274182 6.749091z m-153.6-67.304727l-50.548364 13.544727 40.680727 151.738182 50.548364-13.498182-40.634182-151.738182z m653.963636-392.052364l50.548364-13.544727-40.680727-151.738182-50.548364 13.544727 40.634182 151.738182z"></path></symbol><symbol id="ic-like" viewBox="0 0 1084 1024"><path d="M728.064 343.943529c-17.648941-2.891294-23.552-20.239059-26.503529-28.912941V104.026353C701.560471 46.200471 654.396235 0 595.425882 0c-53.007059 0-97.28 40.478118-106.134588 89.569882-29.997176 184.862118-138.541176 255.457882-217.630118 280.937412a26.142118 26.142118 0 0 0-18.130823 24.877177v560.067764c0 19.817412 16.022588 35.84 35.84 35.84h535.973647c56.018824-11.565176 94.328471-31.804235 120.892235-86.738823l120.832-416.105412c23.552-75.173647-14.757647-147.395765-100.231529-144.564706h-238.772706z m-571.813647 31.744H76.619294C35.358118 375.687529 0 410.383059 0 450.861176v462.426353c0 43.369412 32.406588 78.004706 76.619294 78.004706h79.631059c27.708235 0 50.115765-22.407529 50.115765-50.115764V425.863529a50.115765 50.115765 0 0 0-50.115765-50.115764z"></path></symbol><symbol id="ic-reply" viewBox="0 0 1092 1024"><path d="M173.24799969 781.568C95.168 781.568 32 723.07200031 32 650.94399969V162.56C32 90.49599969 95.04000031 32 172.99200031 32h742.01599969C992.96 32 1056.00000031 90.49599969 1056.00000031 162.62400031v488.31999938c0 72.06400031-63.36 130.62400031-141.12 130.62400031h-343.68l-287.55200062 196.224a12.79999969 12.79999969 0 0 1-19.968-10.87999969l5.63200031-185.34400031H173.24799969z"></path></symbol><symbol id="ic-shang" viewBox="0 0 1024 1024"><path d="M827.512471 177.88486233c35.056941 0 61.982118 8.914824 79.028705 26.684236 17.950118 17.769412 26.985412 44.453647 26.985412 80.052706 0 17.769412-3.614118 43.610353-10.842353 77.402353-3.553882 17.769412-14.336 65.776941-50.236235 65.776941a48.549647 48.549647 0 0 1-35.056941-15.058824 39.273412 39.273412 0 0 1-3.614118-48.971294c9.938824-30.238118 15.299765-56.922353 15.299765-77.402353 0-26.684235-7.228235-26.684235-13.492706-26.684235H189.861647c-0.843294 0-1.807059 0-3.553882 1.807059-1.807059 1.807059-1.807059 2.650353-1.807059 4.457411v108.483765c0 17.829647-11.685647 39.152941-43.971765 39.152941-31.442824 0-43.128471-21.323294-43.12847-39.152941v-110.230588c0-29.394824 8.071529-50.718118 25.118117-65.837177 16.203294-14.275765 38.610824-21.383529 70.053647-21.383529h54.814118a267.685647 267.685647 0 0 0-27.828706-33.731765c-19.757176-22.287059-14.396235-40.96-9.878588-50.778353 8.071529-15.058824 21.504-23.973647 36.743529-23.973647a43.369412 43.369412 0 0 1 30.59953 13.312c3.614118 3.614118 8.071529 8.914824 13.43247 16.022589 5.421176 7.107765 11.685647 16.022588 18.913883 26.684235 11.625412 17.769412 22.407529 35.538824 32.286117 53.36847h128.421647V75.60533333c0-17.769412 10.842353-39.152941 43.128471-39.152941 32.346353 0 43.971765 21.383529 43.971765 39.152941v102.279529h136.553411c7.168-10.661647 15.239529-21.323294 22.467765-32.88847 9.818353-15.119059 19.696941-32.045176 29.635765-48.971294a45.537882 45.537882 0 0 1 22.407529-23.973647 40.357647 40.357647 0 0 1 30.539294-0.90353c7.228235 2.650353 13.492706 7.107765 18.853647 12.468706a35.659294 35.659294 0 0 1 11.685647 25.780706c0 11.565176-4.457412 27.587765-34.093176 68.487529h32.286118z m-532.540236 341.534118a46.622118 46.622118 0 0 1-30.539294-16.022588 57.825882 57.825882 0 0 1-16.143059-31.081412 169.381647 169.381647 0 0 1-3.614117-40.056471V388.76862733c0-15.119059 1.807059-27.587765 3.614117-37.345882 2.650353-12.468706 8.071529-22.287059 15.23953-30.298353 7.228235-8.854588 17.950118-14.215529 31.442823-15.962353 9.878588-0.903529 19.757176-1.807059 32.346353-1.807059h367.314824c30.539294 0 52.043294 8.011294 65.536 23.130353 11.685647 14.215529 17.950118 35.538824 17.950117 63.126588v46.260706c0 29.394824-6.264471 50.718118-20.660705 64.933647-13.432471 13.372235-34.093176 20.48-62.825412 20.48H326.415059c-12.589176 0-22.467765 0-31.442824-1.807059z m32.346353-129.867294h-0.903529v43.610353c0 5.360941 0.903529 7.107765 1.807059 8.011294h366.411294c-0.903529 0 0-2.650353 0-7.107765v-49.814588H327.318588v5.300706z m577.41553 527.480471c15.299765 11.565176 23.371294 24.877176 19.757176 39.152941 0 16.865882-9.878588 31.984941-26.925176 38.189176a36.743529 36.743529 0 0 1-17.046589 3.614118 64.451765 64.451765 0 0 1-31.442823-9.818353 2255.149176 2255.149176 0 0 0-139.14353-74.691765 2297.976471 2297.976471 0 0 0-155.407058-71.198117c-8.071529-4.397176-33.249882-15.058824-33.249883-39.152942 0-0.843294 0.903529-1.746824 0.90353-3.493647-5.421176 13.312-12.589176 26.684235-19.757177 39.152941-30.539294 53.308235-91.557647 93.364706-180.525176 119.145412-84.389647 24.937412-144.564706 37.345882-184.982588 37.345883-34.153412 0-45.778824-22.226824-45.778824-41.803295 0-8.854588 3.614118-36.442353 44.875294-44.453647 86.196706-11.565176 152.696471-26.684235 199.378824-43.610353 43.971765-16.865882 76.318118-39.152941 96.075294-66.68047 19.757176-27.587765 30.539294-71.137882 31.442823-129.867294 0-19.576471 9.035294-33.792 24.274824-39.996236H272.504471c-6.264471 0-8.975059 0-8.975059 14.21553v176.128c0 24.877176-17.046588 41.803294-43.068236 41.803294-25.178353 0-42.224941-16.022588-42.224941-41.803294v-184.139294c0-29.334588 8.071529-51.621647 23.311059-66.740706 15.299765-15.058824 37.767529-22.226824 68.306824-22.226824h489.411764c33.249882 0 55.717647 7.107765 70.053647 21.38353 13.492706 14.215529 20.660706 36.442353 20.660706 67.584v180.525176c0 24.937412-17.046588 41.803294-43.12847 41.803294-25.118118 0-42.164706-15.962353-42.164706-41.803294v-170.767059a31.503059 31.503059 0 0 0-1.807059-13.312c-1.807059-0.903529-3.614118-0.903529-7.228235-0.903529H524.890353c15.239529 6.204235 25.118118 20.48 25.118118 40.056471 0 37.345882-6.264471 72.884706-17.950118 107.580235 0.903529-0.843294 0.903529-1.807059 1.807059-2.650353 4.457412-8.914824 16.143059-15.119059 29.635764-15.119059 6.264471 0 15.239529 1.807059 54.814118 18.672941l98.785882 46.260706c20.600471 9.758118 40.357647 19.576471 60.114824 28.431059 20.660706 8.914824 40.417882 18.672941 59.271529 28.491294 19.757176 9.758118 35.056941 17.769412 45.778824 23.130353 9.938824 5.300706 16.263529 8.914824 18.913882 9.758118l3.614118 1.807059z"></path></symbol><symbol id="ic-diamond" viewBox="0 0 1026 1024"><path d="M751.144277 307.2l-123.016533-238.933333h159.778133a81.92 81.92 0 0 1 59.1872 25.258666l160.256 167.492267A27.306667 27.306667 0 0 1 987.620011 307.2h-236.475734z m270.506667 111.547733L640.927744 946.039467a27.306667 27.306667 0 0 1-48.128-24.234667L766.504277 375.466667h-56.388266l-170.5984 590.165333a27.306667 27.306667 0 0 1-52.462934 0.034133L315.500544 375.466667H259.112277l174.523734 545.5872a27.306667 27.306667 0 0 1-48.128 24.302933L5.160277 418.747733A27.306667 27.306667 0 0 1 27.346944 375.466667H999.464277a27.306667 27.306667 0 0 1 22.152534 43.281066zM18.301611 261.0176L178.557611 93.525333A81.92 81.92 0 0 1 237.744811 68.266667h159.744L274.506411 307.2H38.030677a27.306667 27.306667 0 0 1-19.729066-46.1824zM453.877077 68.266667h117.896534l122.9824 238.933333H330.894677l122.9824-238.933333z"></path></symbol><symbol id="ic-money" viewBox="0 0 1024 1024"><path d="M884.363636 512C884.363636 306.349242 717.650758 139.636364 512 139.636364 306.349242 139.636364 139.636364 306.349242 139.636364 512 139.636364 717.650758 306.349242 884.363636 512 884.363636 717.650758 884.363636 884.363636 717.650758 884.363636 512ZM46.545455 512C46.545455 254.936553 254.936553 46.545455 512 46.545455 769.063447 46.545455 977.454545 254.936553 977.454545 512 977.454545 769.063447 769.063447 977.454545 512 977.454545 254.936553 977.454545 46.545455 769.063447 46.545455 512ZM470.626262 520.334527 346.368469 520.334527C335.022727 520.334527 325.818182 511.082366 325.818182 499.669243L325.818182 478.939206C325.818182 467.431177 335.018859 458.273923 346.368469 458.273923L459.41918 458.273923 362.752701 343.071299C355.558764 334.497899 356.572921 321.312715 365.315879 313.976502L381.196011 300.65149C390.011671 293.254272 402.96653 294.447111 410.293884 303.179511L512.303444 424.749773 614.313007 303.179511C621.64036 294.447111 634.595221 293.254272 643.410879 300.65149L659.29101 313.976502C668.033969 321.312715 669.048129 334.497899 661.854189 343.071299L565.18771 458.273923 677.63153 458.273923C688.977273 458.273923 698.181818 467.526083 698.181818 478.939206L698.181818 499.669243C698.181818 511.177272 688.981141 520.334527 677.63153 520.334527L553.373738 520.334527 553.373738 582.395136 677.63153 582.395136C688.977273 582.395136 698.181818 591.647297 698.181818 603.060419L698.181818 623.790457C698.181818 635.298486 688.981141 644.455741 677.63153 644.455741L553.373738 644.455741 553.373738 737.562275C553.373738 748.871415 544.025139 758.175739 532.493056 758.175739L491.506944 758.175739C479.797853 758.175739 470.626262 748.946776 470.626262 737.562275L470.626262 644.455741 346.368469 644.455741C335.022727 644.455741 325.818182 635.203579 325.818182 623.790457L325.818182 603.060419C325.818182 591.552391 335.018859 582.395136 346.368469 582.395136L470.626262 582.395136 470.626262 520.334527Z"></path></symbol><symbol id="ic-others" viewBox="0 0 1024 1024"><path d="M232.727273 579.87878833C271.28679 579.87878833 302.545455 548.62012233 302.545455 510.06060633 302.545455 471.50108933 271.28679 440.24242433 232.727273 440.24242433 194.167756 440.24242433 162.909091 471.50108933 162.909091 510.06060633 162.909091 548.62012233 194.167756 579.87878833 232.727273 579.87878833ZM512 579.87878833C550.559516 579.87878833 581.818182 548.62012233 581.818182 510.06060633 581.818182 471.50108933 550.559516 440.24242433 512 440.24242433 473.440484 440.24242433 442.181818 471.50108933 442.181818 510.06060633 442.181818 548.62012233 473.440484 579.87878833 512 579.87878833ZM791.272727 579.87878833C829.832243 579.87878833 861.090909 548.62012233 861.090909 510.06060633 861.090909 471.50108933 829.832243 440.24242433 791.272727 440.24242433 752.713211 440.24242433 721.454545 471.50108933 721.454545 510.06060633 721.454545 548.62012233 752.713211 579.87878833 791.272727 579.87878833Z"></path></symbol><symbol id="ic-requests" viewBox="0 0 1024 1024"><path d="M418.909091 372.363636 418.909091 698.181818 605.090909 698.181818 605.090909 372.363636 696.24367 372.363638 511.582813 151.061383 326.921959 372.363638 418.909091 372.363636ZM325.818182 791.272727 325.818182 465.454545 139.636364 465.454545 512 10.219745 884.363636 465.454545 698.181818 465.454545 698.181818 791.272727 325.818182 791.272727ZM791.549193 930.909091C842.809195 930.909091 884.363636 889.589313 884.363636 837.818182L884.363636 744.727273 977.454545 744.727273 977.454545 884.363636C977.454545 961.482668 914.929478 1024 838.088048 1024L185.911951 1024C108.94196 1024 46.545455 961.32575 46.545455 884.363636L46.545455 744.727273 139.636364 744.727273 139.636364 837.818182C139.636364 889.230871 181.271913 930.909091 232.450806 930.909091L791.549193 930.909091Z"></path></symbol><symbol id="ic-follows" viewBox="0 0 1024 1024"><path d="M742.39037 893.84038533C732.980703 903.25005233 718.025272 903.19522133 708.767223 893.93717233L565.458115 753.71907433C556.207048 744.46800633 556.2434 729.40742933 565.554902 720.09592233L605.034543 682.83743133C614.444209 673.42776433 629.399645 673.48259533 638.657694 682.74064433L728.38723 766.49557833 941.491782 540.05939833C950.503205 531.04797933 965.609342 531.03876833 974.920848 540.35027433L1010.521307 576.49106033C1019.930973 585.90072733 1019.963043 600.76926333 1010.812183 609.92012233L742.39037 893.84038533ZM139.636364 859.15151533C139.636364 859.15151533 140.67734 830.50210333 143.721266 818.93653533 149.029303 798.76835333 158.415813 778.50853133 172.872966 759.57276033 185.195819 743.43246833 200.763606 728.89474933 220.104544 716.30744833 248.816792 697.62118933 341.214879 652.42733033 332.078782 657.40617733 390.138425 625.76575033 412.212292 582.79679733 388.559923 518.84814133 384.958515 509.11105133 363.507092 452.78421333 358.209139 437.93037933 342.817466 394.77685333 333.272371 357.97333033 324.783144 304.62989533 312.248334 225.86538933 369.770254 160.96969733 466.26749 160.96969733 571.044971 160.96969733 629.910798 218.91014833 619.986167 306.71758733 613.807085 361.38656133 604.889014 392.41438433 587.2357 428.78513033 587.680116 427.86951433 552.225592 496.14089933 539.29385 524.72497933L624.108763 563.09615833C635.7853 537.28656933 670.418623 470.59648633 670.983024 469.43366333 693.277635 423.50053933 705.13172 382.25771733 712.48809 317.17282433 728.985321 171.21479033 623.998925 67.87878833 466.26749 67.87878833 313.335459 67.87878833 211.18413 183.12496033 232.849136 319.26053733 242.258212 378.38399033 253.244797 420.74554033 270.528472 469.20365633 276.225846 485.17734633 297.956064 542.23624033 301.249676 551.14114433 307.065226 566.86458533 308.380666 564.30394833 287.532892 575.66524233 282.015993 578.67175233 275.594213 581.88642833 265.97112 586.50462633 270.601051 584.28268633 245.145458 596.43114733 238.070951 599.89143433 212.184458 612.55306833 190.997437 624.18127233 169.326586 638.28490833 140.984774 656.73008533 117.593202 678.57391433 98.881863 703.08175233 60.377931 753.51364533 47.027784 804.23828133 46.549412 840.92027533L46.545455 947.98348733 587.235705 947.98345933 512 859.15151533 139.636364 859.15151533Z"></path></symbol><symbol id="ic-chats" viewBox="0 0 1024 1024"><path d="M124.121212 139.636364C88.436364 139.636364 47.010909 181.527273 46.545455 217.212121L46.545455 799.030305C46.545455 842.472727 88.436364 884.363636 124.121212 876.606059L899.878786 876.606059C935.563636 884.363636 977.454545 842.472727 977.454545 799.030305L977.454545 217.212121C977.454545 181.527273 935.563636 139.636364 899.878786 139.636364L124.121212 139.636364ZM512 473.016869 139.636364 232.727273 884.363636 232.727273 512 473.016869ZM139.636364 791.272727 139.636364 331.612007 512 578.515503 884.363636 331.612007 884.363636 791.272727 139.636364 791.272727Z"></path></symbol><symbol id="ic-comments" viewBox="0 0 1024 1024"><path d="M977.454545 164.91403167C977.454545 113.60050467 935.731963 71.75757567 884.264546 71.75757567L139.735452 71.75757567C88.181004 71.75757567 46.545455 113.46514167 46.545455 164.91403167L46.545455 676.78293967C46.545455 728.09646367 88.22568 769.93939367 139.640844 769.93939367L186.181818 769.93939367 186.181818 956.12121167 512 769.93939367 884.524167 769.93939367C935.858506 769.93939367 977.454545 728.23182767 977.454545 676.78293967L977.454545 164.91403167ZM884.363636 164.84848467L884.363636 676.84848467 502.393986 676.84848467 279.272727 769.93939367 279.272727 676.84848467 139.636364 676.84848467 139.636364 164.84848467 884.363636 164.84848467Z"></path></symbol><symbol id="ic-likes" viewBox="0 0 1024 1024"><path d="M511.646501 852.318427C513.3925 850.741015 516.884503 847.586202 516.884503 847.586202 738.668074 646.043071 808.239081 574.380446 853.64177 489.88787 874.584837 450.913673 884.363636 415.390578 884.363636 379.345455 884.363636 287.398144 813.401856 216.436364 721.454545 216.436364 669.217853 216.436364 616.89613 241.028421 582.874945 280.979901L512 364.209197 441.125053 280.979901C407.103871 241.028421 354.782148 216.436364 302.545455 216.436364 210.598144 216.436364 139.636364 287.398144 139.636364 379.345455 139.636364 415.547805 149.501383 451.227391 170.635978 490.39044 216.182926 574.790321 286.220326 646.813794 507.042118 847.054141 507.042118 847.054141 490.96233 871.005342 511.646501 852.318427ZM512 220.625455 578.083025 164.351628C620.609936 138.33686 670.384463 123.345455 721.454545 123.345455 864.814545 123.345455 977.454545 235.985455 977.454545 379.345455 977.454545 555.287273 819.2 698.647273 579.490909 916.48L512 977.454545 444.509091 916.014545C204.8 698.647273 46.545455 555.287273 46.545455 379.345455 46.545455 235.985455 159.185455 123.345455 302.545455 123.345455 353.615536 123.345455 403.390064 138.33686 445.916975 164.351628L512 220.625455Z"></path></symbol><symbol id="ic-nav-mode" viewBox="0 0 1024 1024"><path d="M194.56 597.333333l-64.853333 166.4c-2.858667 9.088-3.413333 15.786667-1.706667 20.053334 1.706667 4.266667 10.24 6.954667 25.6 8.106666l56.32 4.266667v24.746667a521.557333 521.557333 0 0 0-34.56-1.28c-17.365333-0.298667-40.832-0.426667-70.4-0.426667s-53.034667 0.128-70.4 0.426667c-17.365333 0.298667-28.885333 0.725333-34.56 1.28v-24.746667l53.76-4.266667c18.773333-1.706667 31.872-12.245333 39.253333-31.573333L292.693333 256h41.813334l188.586666 498.346667c3.968 9.685333 7.68 16.213333 11.093334 19.626666 3.413333 3.413333 9.685333 6.528 18.773333 9.386667l46.933333 14.506667v23.893333a1946.538667 1946.538667 0 0 0-99.84-2.56h-71.68c-45.525333 0-82.773333 0.853333-111.786666 2.56v-23.893333l53.76-8.533334c16.512-2.858667 25.898667-6.272 28.16-10.24 2.261333-3.968 1.152-11.648-3.413334-23.04L336.213333 597.333333H194.56z m127.146667-39.253333L271.36 398.506667l-61.44 159.573333h111.786667z m427.52 273.92c-23.338667 0-43.392-4.138667-60.16-12.373333a110.805333 110.805333 0 0 1-40.96-33.706667 146.816 146.816 0 0 1-23.466667-50.346667c-5.12-19.328-7.68-40.106667-7.68-62.293333 0-30.165333 4.565333-56.874667 13.653333-80.213333 9.088-23.338667 21.333333-42.965333 36.693334-58.88a153.6 153.6 0 0 1 53.76-36.266667 171.946667 171.946667 0 0 1 64.853333-12.373333c15.914667 0 29.866667 1.152 41.813333 3.413333 11.946667 2.261333 21.888 4.821333 29.866667 7.68 9.685333 2.858667 17.621333 6.272 23.893333 10.24l56.32-31.573333 7.68 2.56v262.826666c0 22.741333 9.685333 33.578667 29.013334 32.426667 4.565333 0 8.106667-0.725333 10.666666-2.133333s4.992-2.688 7.253334-3.84c2.261333-1.706667 4.266667-3.413333 5.973333-5.12l5.12 11.946666c-4.565333 10.794667-10.538667 20.48-17.92 29.013334-6.272 7.381333-14.634667 14.08-25.173333 20.053333-10.538667 5.973333-23.466667 8.96-38.826667 8.96-25.045333 0-42.794667-7.552-53.333333-22.613333-10.538667-15.061333-15.786667-33.408-15.786667-55.04v-20.48a181.888 181.888 0 0 1-12.373333 36.266666 129.92 129.92 0 0 1-20.053334 31.146667 92.373333 92.373333 0 0 1-29.44 22.186667 93.44 93.44 0 0 1-41.386666 8.533333z m103.253333-196.266667c0-11.946667-0.554667-24.448-1.706667-37.546666a143.872 143.872 0 0 0-7.68-36.266667 66.858667 66.858667 0 0 0-18.346666-27.733333c-8.234667-7.381333-19.498667-11.093333-33.706667-11.093334-7.978667 0-16.341333 2.133333-25.173333 6.4-8.832 4.266667-16.938667 11.221333-24.32 20.906667-7.381333 9.685333-13.525333 22.912-18.346667 39.68-4.821333 16.768-7.253333 37.418667-7.253333 61.866667 0 17.066667 1.28 33.28 3.84 48.64 2.56 15.36 6.698667 28.714667 12.373333 40.106666 5.674667 11.392 12.672 20.352 20.906667 26.88 8.234667 6.528 18.048 9.813333 29.44 9.813334 11.392 0 21.333333-3.712 29.866666-11.093334 8.533333-7.381333 15.786667-17.194667 21.76-29.44 5.973333-12.245333 10.538667-26.325333 13.653334-42.24 3.114667-15.914667 4.693333-32.426667 4.693333-49.493333v-9.386667z"></path></symbol><symbol id="ic-write" viewBox="0 0 1024 1024"><path d="M151.007 942.26766666c-22.993 21.261-64.594 64.683-43.381-35.512 37.218-163.524 447.875-792.517 794.003-852.861 97.053 0-180.459 232.311-180.459 232.311 0 0 95.338 11.846 157.962-54.296-37.533 195.818-214.91 195.149-260.719 210.729 53.59 7.89 93.441 31.594 176.379 7.368-20.222 55.519-100.075 123.839-387.175 191.454-126.92 45.617-233.617 279.547-256.61 300.808z"></path></symbol><symbol id="ic-night" viewBox="0 0 1024 1024"><path d="M386.573124 0C340.147815 173.910685 384.73085 366.612567 521.059141 502.940859 657.387432 639.26915 850.089314 683.852184 1024 637.426876 1001.155802 722.908399 956.572765 804.336916 889.51398 871.395701 686.126909 1074.782772 355.991373 1074.782772 152.6043 871.395701-50.782772 668.00863-50.782772 337.87309 152.6043 134.486017 219.663081 67.427236 301.091602 22.8442 386.573124 0Z"></path></symbol><symbol id="ic-mark" viewBox="0 0 1024 1024"><path d="M268.190476 113.777778C214.552381 113.777778 171.154286 155.291291 171.154286 206.03003L170.666667 967.111111 512 828.732735 853.333333 967.111111 853.333333 206.03003C853.333333 155.291291 809.447617 113.777778 755.809525 113.777778L268.190476 113.777778Z"></path></symbol><symbol id="ic-user" viewBox="0 0 1081 1024"><path d="M803.557507 705.46529267C921.627438 734.68811367 1009.013675 841.17086467 1009.013675 968.09948167L1009.013675 999.65574867 113.777778 999.65574867 113.777778 968.09948167C113.777778 845.98765767 194.87339 742.62628167 306.138642 709.26557267 386.042902 689.94662967 446.772745 624.07875167 455.097973 555.06783567 413.092784 526.09210167 380.671395 482.61667367 369.546671 434.01441967L331.247877 266.69273867C301.999138 138.90939267 384.447284 35.55555567 515.334601 35.55555567L604.020878 35.55555567C735.179184 35.55555567 819.313243 139.39951167 792.544825 267.49752267L757.903491 433.27071867C747.227432 484.36012067 713.120956 529.80140967 668.826761 558.82664367 675.211167 624.51970267 729.457687 683.91321067 803.557507 705.46529267Z"></path></symbol><symbol id="ic-setting" viewBox="0 0 1024 1024"><path d="M846.327484 515.083444C846.327484 499.504829 844.9529 484.842604 843.120122 470.180378L939.799171 394.578276C948.504866 387.705358 950.795839 375.334105 945.297505 365.253825L853.658596 206.718508C848.160262 196.638228 835.78901 192.972672 825.708726 196.638228L711.618281 242.457684C687.792168 224.129902 662.133271 209.009481 634.183401 197.554617L616.772011 76.13306C615.397427 65.136391 605.775343 56.888889 594.320475 56.888889L411.042655 56.888889C399.587791 56.888889 389.965705 65.136391 388.591122 76.13306L371.179729 197.554617C343.22986 209.009481 317.570966 224.588096 293.744849 242.457684L179.654404 196.638228C169.11593 192.514478 157.202871 196.638228 151.704536 206.718508L60.065625 365.253825C54.109096 375.334105 56.858263 387.705358 65.56396 394.578276L162.243011 470.180378C160.410233 484.842604 159.035649 499.963024 159.035649 515.083444 159.035649 530.203865 160.410233 545.324285 162.243011 559.986511L65.56396 635.588614C56.858263 642.461531 54.567291 654.832782 60.065625 664.913067L151.704536 823.448383C157.202871 833.528661 169.574124 837.194217 179.654404 833.528661L293.744849 787.709207C317.570966 806.036986 343.22986 821.15741 371.179729 832.612272L388.591131 947.866943C389.965715 958.86361 399.587801 967.111111 411.042665 967.111111L594.320486 967.111111C605.775349 967.111111 615.397439 958.86361 616.772022 947.866943L634.183401 832.612272C662.133271 821.15741 687.792168 805.578792 711.618281 787.709207L825.708726 833.528661C836.247205 837.652412 848.160262 833.528661 853.658596 823.448383L945.297505 664.913067C950.795839 654.832782 948.504866 642.461531 939.799171 635.588614L843.120122 559.986511C844.9529 545.324285 846.327484 530.662059 846.327484 515.083444ZM502.681566 675.45154C414.250017 675.45154 342.313471 603.514994 342.313471 515.083444 342.313471 426.651895 414.250017 354.71535 502.681566 354.71535 591.113114 354.71535 663.04966 426.651895 663.04966 515.083444 663.04966 603.514994 591.113114 675.45154 502.681566 675.45154L502.681566 675.45154Z"></path></symbol><symbol id="ic-wallet" viewBox="0 0 1081 1024"><path d="M78.590372 320.640733C79.612385 263.784132 108.255224 220.849417 161.254046 208.613675L811.774629 58.429164C843.73446 51.050656 875.603143 70.885317 882.986092 102.864395L930.36408 264.731771C930.36408 264.731771 432.674221 267.670638 193.893052 264.731771 191.508185 264.702418 137.002048 273.909722 137.002047 320.464627L888.060649 320.640726C942.735462 320.640726 988.818119 385.402493 988.818119 439.966797L988.818119 835.991046C988.818119 890.695509 928.709194 947.609862 874.118087 947.609862L193.893052 947.609862C139.218237 947.609862 78.590372 890.555352 78.590372 835.991046L78.590372 320.640733ZM870.350433 600.907349C870.350433 562.701243 839.378261 531.729073 801.172156 531.729073 762.96605 531.729073 731.993879 562.701243 731.993879 600.907349 731.993879 639.113461 762.96605 670.085626 801.172156 670.085626 839.378261 670.085626 870.350433 639.113461 870.350433 600.907349Z"></path></symbol><symbol id="ic-like-filled" viewBox="0 0 1024 1024"><path d="M455.286273 907.310814C215.315919 689.706627 56.888889 546.190377 56.888889 370.056797 56.888889 226.540546 169.651657 113.777778 313.167908 113.777778 394.24527 113.777778 472.0609 151.520688 522.850741 211.163805 573.640585 151.520688 651.45621 113.777778 732.533578 113.777778 876.049829 113.777778 988.812595 226.540546 988.812595 370.056797 988.812595 546.190377 830.385567 689.706627 590.415212 907.776774L522.850741 968.817778 455.286273 907.310814Z"></path></symbol><symbol id="ic-feedback" viewBox="0 0 1024 1024"><path d="M158.037561 937.474543C158.037561 937.474543 428.526853 971.883105 479.47676 768.097638L795.921232 768.097638C859.047925 768.097638 910.222222 716.754256 910.222222 654.123816L910.222222 227.7516C910.222222 164.805596 859.18947 113.777778 796.11115 113.777778L227.888848 113.777778C164.867044 113.777778 113.777778 165.12116 113.777778 227.7516L113.777778 654.123816C113.777778 717.069824 164.241867 768.097638 227.072055 768.097638L285.060607 768.097638C254.825383 906.665296 158.037561 937.474543 158.037561 937.474543ZM284.444444 512 625.777778 512 625.777778 597.333333 284.444444 597.333333 284.444444 512 284.444444 512ZM284.473374 312.888889 739.584484 312.888889 739.584484 398.222222 284.473374 398.222222 284.473374 312.888889 284.473374 312.888889Z"></path></symbol><symbol id="ic-signout" viewBox="0 0 1024 1024"><path d="M376.88888867 568.888889L746.66666667 568.888889 632.88888867 682.666667 703.99999967 755.238935 945.77777767 540.444444 945.77777767 483.555556 703.99999967 270.947385 632.88888867 341.333333 746.66666667 455.111111 376.88888867 455.111111 376.88888867 568.888889ZM489.07269967 113.777778L489.07269967 227.888848 206.20427767 227.888848 206.20427767 796.111167 489.07269967 796.111167 489.07269967 910.222222 206.20427967 910.222222C143.37645767 910.222222 92.44444467 859.18947 92.44444467 796.11115L92.44444467 227.888848C92.44444467 164.867044 143.37274867 113.777778 206.20427967 113.777778L489.07269967 113.777778Z"></path></symbol><symbol id="ic-nav-discover" viewBox="0 0 1024 1024"><path d="M13.3565216 512C13.3565216 236.60633067 236.60633067 13.3565216 512 13.3565216S1010.6434784 236.60633067 1010.6434784 512 787.39366933 1010.6434784 512 1010.6434784 13.3565216 787.39366933 13.3565216 512z m926.05217387 0a427.40869547 427.40869547 0 1 0-854.81739094 0 427.40869547 427.40869547 0 0 0 854.81739094 0z m-321.3638496-253.548336c120.29180267-82.53736853 173.6704-39.4165792 119.4369856 95.9295072l-104.9525792 261.6691008-217.9784352 148.8332064c-120.434272 82.1574496-175.90242347 37.70694507-124.13848107-98.6364288l93.93493333-247.42214507 233.65008747-160.37324053zM512 583.23478293a71.23478293 71.23478293 0 1 0 0-142.46956586 71.23478293 71.23478293 0 0 0 0 142.46956586z"></path></symbol><symbol id="ic-nav-notification" viewBox="0 0 1024 1024"><path d="M513.024 1001.828174A111.88313 111.88313 0 0 0 625.39687 890.434783H400.695652a111.88313 111.88313 0 0 0 112.328348 111.393391z m-320.823652-489.293913v5.030956c0 43.408696-13.445565 84.591304-36.062609 122.301218-8.013913 13.312-16.562087 25.154783-25.065739 35.350261-4.897391 5.921391-8.592696 9.794783-10.329043 11.486608l-3.250087 3.650783C57.433043 768.934957 96.478609 845.913043 196.118261 845.913043h634.434782c99.906783 0 135.43513-75.063652 74.306783-153.11026l-1.736348-2.181566-2.048-1.869913a180.535652 180.535652 0 0 1-11.53113-11.976347 298.206609 298.206609 0 0 1-27.603478-36.151653c-24.709565-38.021565-39.357217-79.070609-39.357218-121.366261 0-2.31513 0-4.630261 0.089044-6.945391l-0.044522-76.755478c0-132.096-84.591304-258.626783-189.350957-283.202783C624.951652 91.447652 571.65913 44.521739 507.458783 44.521739 437.426087 44.521739 395.931826 92.16 382.085565 151.863652 268.332522 200.214261 192.333913 310.761739 192.333913 435.556174v63.933217c-0.133565 3.116522-0.133565 6.233043-0.089043 13.089392z m65.80313-72.525913c0-105.427478 67.31687-198.210783 166.199652-232.848696l21.99374-7.657739v-29.028174c0-33.124174 27.38087-60.237913 61.261913-60.237913 33.836522 0 61.217391 27.113739 61.217391 60.237913v29.028174l21.993739 7.702261C689.508174 241.797565 756.869565 334.625391 756.869565 440.05287l0.089044 77.06713-0.089044 7.568696c0 56.765217 18.788174 109.968696 49.775305 158.230261 18.432 28.672 36.953043 49.597217 49.997913 61.618086l-3.739826-4.096c28.093217 36.285217 22.216348 48.88487-22.394435 48.88487H196.118261c-45.456696 0-53.426087-15.894261-26.178783-52.001391l-3.250087 3.695304c12.02087-11.798261 29.072696-32.411826 45.946435-60.816696 28.226783-47.549217 45.278609-100.396522 45.278609-157.250782v-5.431652l0.044522-11.842783V440.008348z"></path></symbol><symbol id="ic-nav-follow" viewBox="0 0 1024 1024"><path d="M725.25913 780.14701467L721.474783 780.05797067H868.173913c24.620522 0 44.521739-19.945739 44.521739-44.744347V134.71536267A44.521739 44.521739 0 0 0 868.08487 89.97101467H155.91513C131.33913 89.97101467 111.304348 110.00579667 111.304348 134.71536267v600.598261A44.432696 44.432696 0 0 0 155.737043 780.05797067h146.832696l-3.784348 0.089044c69.053217-3.873391 154.757565 43.186087 213.036522 106.184348 51.778783-60.594087 125.373217-111.170783 213.437217-106.184348zM44.521739 735.31362367V134.71536267A111.482435 111.482435 0 0 1 155.91513 23.18840567h712.16974A111.304348 111.304348 0 0 1 979.478261 134.71536267v600.598261a111.34887 111.34887 0 0 1-111.304348 111.526956h-146.69913c-66.960696-3.784348-172.78887 74.885565-201.861566 145.67513-4.541217 11.130435-10.685217 10.596174-15.449043-0.756869-29.606957-70.611478-134.90087-148.702609-201.594435-144.918261H155.737043A111.215304 111.215304 0 0 1 44.521739 735.31362367zM489.73913 179.01449267h44.52174V735.53623167h-44.52174V179.01449267z m333.913044 178.086957V290.31884067H623.304348v66.782609h200.347826zM623.304348 512.92753667h200.347826v-66.782609H623.304348V512.92753667zM200.347826 357.10144967H400.695652V290.31884067H200.347826v66.782609z m0 155.826087H400.695652v-66.782609H200.347826V512.92753667z"></path></symbol><symbol id="ic-nav-download" viewBox="0 0 1024 1024"><path d="M222.608696 133.342609C222.608696 84.279652 262.41113 44.521739 311.785739 44.521739h400.428522C761.455304 44.521739 801.391304 84.680348 801.391304 133.342609v757.314782A88.909913 88.909913 0 0 1 712.214261 979.478261H311.785739A89.266087 89.266087 0 0 1 222.608696 890.657391V133.342609zM445.217391 912.695652c0-12.288 9.616696-22.26087 22.038261-22.260869h89.488696c12.154435 0 22.038261 10.329043 22.038261 22.260869 0 12.288-9.616696 22.26087-22.038261 22.26087h-89.488696a22.394435 22.394435 0 0 1-22.038261-22.26087zM289.391304 845.913043h445.217392V111.304348h-445.217392V845.913043zM356.173913 489.73913l155.826087 184.141913L667.826087 489.73913h-89.043478V356.173913h-133.565218v133.565217H356.173913z"></path></symbol><symbol id="ic-paid" viewBox="0 0 1024 1024"><path d="M511.850132 0C229.23293 0 0.000088 229.132871 0.000088 511.850044s229.132871 511.850044 511.850044 511.850044 511.850044-229.232842 511.850044-511.850044-229.132871-511.850044-511.850044-511.850044z m226.833545 576.031241c29.191448 0 52.984477 23.693059 52.984477 52.884506 0 14.195841-5.398418 27.491946-15.195548 37.289076-9.997071 9.997071-23.293176 15.39549-37.588988 15.395489H564.034843v173.649127c0 29.091477-23.593088 52.584594-52.484623 52.584594-29.091477 0-52.884506-23.693059-52.984478-52.684565V681.800254H285.016587c-29.191448 0-52.884506-23.693059-52.884507-52.884507s23.693059-52.884506 52.884507-52.884506h173.449185V454.766768H284.816646c-29.191448 0-52.884506-23.593088-52.884507-52.584595s23.693059-52.584594 52.884507-52.584594H474.161173L330.703202 205.939666c-10.097042-9.997071-15.595431-23.193205-15.595431-37.289075 0-14.09587 5.498389-27.491946 15.595431-37.489017 9.997071-9.997071 23.093234-15.39549 37.189105-15.39549 14.09587 0 27.292004 5.498389 37.289075 15.595431l116.46588 116.465879L637.813229 131.261544c9.997071-10.097042 23.193205-15.595431 37.389046-15.595431 14.09587 0 27.192034 5.498389 37.189104 15.39549 20.493996 20.593967 20.593967 54.184126 0 74.678122L569.23332 349.597579h169.350386c29.191448 0 52.984477 23.593088 52.984477 52.584594 0 27.591916-21.493703 50.285268-48.685736 52.484624h-178.947574V576.131212h174.748804v-0.099971z"></path></symbol></svg><div id="__next"><header style="width:100%"><div class="_1CSgtu"><div class="_2oDcyf"><a class="_1AawTM _1OhGeD" href="https://www.jianshu.com/" aria-label="简书" target="_blank" rel="noopener noreferrer"><svg class="wCYvWN" style="width:60px;height:30px" width="60" height="30" focusable="false" aria-hidden="true" viewBox="0 0 106 50" version="1.1"><g><path d="M79.6542664,49.2735656 L75.6602511,49.6932377 L75.6602511,27.3313525 L59.1137321,27.3313525 C58.6314725,27.3313525 57.9655336,26.8821721 57.8498237,26.1776639 L57.5346557,23.1870902 L75.6602511,23.1887295 L75.6602511,12.1260246 L62.1759992,12.1260246 C61.6180832,12.0858607 61.0229458,11.7788934 60.8894344,10.9870902 L60.5819534,7.93790984 L75.6602511,7.93790984 L75.6602511,0.409631148 L81.2074496,0.409631148 L81.2074496,7.93790984 L97.4727855,7.93790984 L97.4727855,23.1887295 L103.836831,23.1887295 L103.836831,38.1235656 C103.836831,42.2026639 100.70174,44.4715164 97.7187702,44.4715164 L92.357274,44.4715164 C91.6217473,44.4715164 91.0290374,43.9440574 90.9659229,43.3719262 L90.6681519,40.5223361 L92.1274725,40.5223361 L95.7933733,40.5223361 C97.0864115,40.5223361 98.3321137,39.6739754 98.3321137,38.1235656 L98.3321137,27.3313525 L81.2074496,27.3313525 L81.2074496,47.4452869 C81.2074496,48.5985656 80.4148771,49.1264344 79.6542664,49.2735656 L79.6542664,49.2735656 Z M81.260045,22.917418 L91.9745412,22.917418 L91.9745412,12.0514344 L81.260045,12.0514344 L81.260045,22.917418 Z M104.57519,13.9920082 L100.167289,13.9920082 C99.5871214,9.9170082 97.5274038,5.26987705 95.0355947,1.96209016 L100.167289,1.96209016 C102.583037,4.95553279 104.693327,8.85922131 105.720556,12.5608607 C105.867015,13.1711066 105.472144,13.9920082 104.57519,13.9920082 L104.57519,13.9920082 Z"></path><path d="M4.98236412,12.0515574 L9.99834885,12.0515574 C11.3953641,13.8056557 12.3169977,15.077377 13.7310053,18.5515574 C13.8337687,18.8339344 13.9130664,20.2007377 12.5900893,20.2007377 L8.57624962,20.2007377 C7.43047863,15.8630328 6.43521145,14.337623 4.97831832,12.0540164 C3.51980687,13.0105738 1.86507405,13.8138525 -4.04580153e-05,14.3802459 L-4.04580153e-05,10.3880328 C2.35987557,9.24172131 4.08662366,7.6892623 5.34608168,5.85278689 C6.43399771,4.2654918 7.18206641,2.47901639 7.58300534,0.409754098 L11.8043947,0.409754098 C12.772555,0.409754098 13.2313489,1.06877049 13.0962191,1.56139344 C12.9129443,2.1392623 12.5342573,2.99377049 12.1640664,3.78270492 L25.2676084,3.78270492 L25.0038221,6.30278689 C24.9370664,6.85483607 24.5227763,7.57532787 23.6181351,7.57532787 L17.5377,7.57532787 C18.2930511,9.24336066 18.7571046,10.7601639 18.9112496,11.3568852 C19.0508298,11.9036066 18.7004634,12.7810656 17.765074,12.7810656 L13.9850817,12.7810656 C13.7127992,10.9581148 13.4073412,9.70811475 12.633784,7.57532787 L9.82963893,7.57532787 C8.54266947,9.20852459 6.93891374,10.7679508 4.98236412,12.0515574 L4.98236412,12.0515574 Z M14.1651198,43.4847541 L14.1651198,22.1413115 L34.8367382,22.1413115 L34.8367382,36.8896721 C34.9253412,41.1093443 31.729158,43.4847541 28.4929214,43.4847541 L14.1651198,43.4847541 Z M35.3776618,49.3056557 C34.6793565,49.3056557 34.1008069,48.7921311 34.0028985,48.0851639 L33.669929,45.2757377 L38.4682496,45.2372131 C39.5310817,45.2372131 40.5696389,44.5277869 40.5696389,42.9769672 L40.5696389,18.4761475 L16.1390664,18.4761475 C15.6288908,18.4761475 15.0078603,18.2769672 14.819326,17.2298361 L14.5478527,14.3802459 L45.940845,14.3802459 L45.940845,43.4048361 C45.940845,45.4257377 44.1275168,49.2339344 39.6552878,49.3056557 L35.3776618,49.3056557 Z M6.84505115,49.2904918 L3.0626313,49.6933607 L3.0626313,20.2007377 L8.42250916,20.2007377 L8.42250916,47.3646721 C8.42250916,48.0146721 8.09399008,49.0794262 6.84505115,49.2904918 L6.84505115,49.2904918 Z M41.1040893,12.617541 L37.1335397,12.617541 C36.8025931,10.8986885 36.5436618,9.44581967 35.7462344,7.47942623 L32.2174863,7.47942623 C31.3132496,8.52245902 30.2645779,9.69581967 28.8404557,10.8204098 C27.3799214,11.9736885 25.5018603,13.1154918 22.9704023,13.9917213 L22.9704023,9.96672131 C27.0331962,7.6904918 29.0237305,4.6007377 29.9906771,0.409754098 L34.2080206,0.409754098 C35.3258756,0.409754098 35.6547992,1.21385246 35.5848069,1.4892623 C35.3121198,2.35811475 34.9075397,2.9892623 34.6032954,3.70360656 L48.620784,3.70360656 L48.3602344,6.23434426 C48.2724405,6.99745902 47.669616,7.47942623 47.0243107,7.47942623 L40.7173107,7.47942623 C41.4892496,9.14459016 41.945616,10.3318852 42.1398145,11.2503279 C42.223158,11.6478689 41.9775779,12.5761475 41.1040893,12.617541 L41.1040893,12.617541 Z M19.1422649,39.6040164 L27.579784,39.6040164 C29.230471,39.6040164 29.861616,38.5290164 29.861616,37.3347541 L29.861616,34.5634426 L19.1693718,34.5589344 L19.1422649,39.6040164 Z M19.1422649,30.6786066 L29.8620206,30.6786066 L29.8620206,26.0220492 L19.1422649,26.0220492 L19.1422649,30.6786066 Z"></path></g></svg></a><div class="_7hb9O4"><i aria-label="ic-nav-mode" tabindex="-1" class="anticon _1nZg8v"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-nav-mode"></use></svg></i><span class="_1jKNin" aria-label="简书钻"><svg class="wCYvWN" style="width:54px;height:24px" width="54" height="24" focusable="false" aria-hidden="true" viewBox="0 0 50 22" version="1.1"><g transform="translate(1.000000, 4.000000)" fill="#EA6F5A" stroke="#EA6F5A" stroke-width="0.5"><path d="M6.97355121,0.977899795 L5.71487604,5.02704222 L14.0382941,5.02704222 L12.7812515,0.977899795 L6.97355121,0.977899795 Z M5.94914309,0.977899795 L5.39898286,0.977899795 C5.34645865,0.977985274 5.29616908,0.99894266 5.25940216,1.03606786 L1.33563333,5.02704222 L4.69046792,5.02704222 L5.94914309,0.977899795 Z M8.80687445,13.8613144 L4.56068234,5.99650966 L1.40664806,5.99650966 L8.80687445,13.8613144 Z M5.67079793,5.99650966 L9.99290234,14.0010793 L14.0962487,5.99650966 L5.67079793,5.99650966 Z M6.61929374,0.00843234872 L14.581108,0.00843234872 C14.8986337,0.00843234872 15.2014667,0.135271015 15.4234898,0.359864308 L19.6476429,4.6562209 C20.0841892,5.10085541 20.0917287,5.80620568 19.6647844,6.25988166 L10.8491606,15.6281688 C10.4068293,16.0970986 9.66444122,16.1231211 9.18970108,15.6863369 C9.1594994,15.6580607 9.1594994,15.6580607 9.13093026,15.6281688 L0.315306487,6.25988166 C-0.111412478,5.80599166 -0.10351395,5.10063881 0.333264249,4.6562209 L4.55741731,0.359864308 C4.7786002,0.135221626 5.08206407,0.00849721138 5.39898286,0.00843234872 L6.62011001,0.00843234872 L6.61929374,0.00843234872 Z M13.8056596,0.977899178 L15.0643348,5.02704222 L18.6452738,5.02704222 L14.721505,1.03606786 C14.6845399,0.998742398 14.6339153,0.977768057 14.581108,0.977899795 L13.8056596,0.977899178 Z M11.1487286,13.8879747 L18.5742591,5.99650966 L15.1949366,5.99650966 L11.1487286,13.8879747 Z"></path></g><g transform="translate(19.000000, 5.000000)"><path d="M5.16425826,0.266666667 C3.98605079,0.266666667 3.03092493,1.22179253 3.03092493,2.4 L3.03092493,8.73301908 L2.96783132,8.90526634 L1.31769477,10.8555055 C1.236217,10.9518012 1.19150756,11.0738592 1.19150756,11.2 C1.19150756,11.4945519 1.43028903,11.7333333 1.72484089,11.7333333 L26.5448138,11.7333333 C27.7230213,11.7333333 28.6781471,10.7782075 28.6781471,9.6 L28.6781471,2.4 C28.6781471,1.22179253 27.7230213,0.266666667 26.5448138,0.266666667 L5.16425826,0.266666667 Z" stroke="#EA6F5A" stroke-width="0.533333333" fill="#EA6F5A"></path><path d="M6.79203604,2 L7.57631592,2 L7.57631592,4.96927224 C7.96845586,4.26091644 8.52725527,3.9115903 9.25271416,3.9115903 C9.96836954,3.9115903 10.5369725,4.17358491 10.9487194,4.71698113 C11.3212523,5.20215633 11.5173223,5.80377358 11.5173223,6.54123989 C11.5173223,7.29811321 11.3212523,7.91913747 10.9487194,8.40431267 C10.527169,8.92830189 9.94876255,9.2 9.21350016,9.2 C8.42922028,9.2 7.87042087,8.87978437 7.52729842,8.2393531 L7.52729842,9.06415094 L6.79203604,9.06415094 L6.79203604,2 Z M9.08605468,4.55202156 C8.62529025,4.55202156 8.25275731,4.72668464 7.97825935,5.09541779 C7.6841544,5.45444744 7.54690542,5.92991914 7.54690542,6.51212938 L7.54690542,6.60916442 C7.54690542,7.17196765 7.6743509,7.62803235 7.92924186,7.97735849 C8.20373982,8.36549865 8.60568326,8.55956873 9.11546518,8.55956873 C9.66446109,8.55956873 10.076208,8.35579515 10.350706,7.96765499 C10.5859899,7.61832884 10.7134354,7.14285714 10.7134354,6.54123989 C10.7134354,5.93962264 10.5859899,5.47385445 10.331099,5.13423181 C10.0467975,4.74609164 9.6350506,4.55202156 9.08605468,4.55202156 Z M14.6250313,3.9115903 C15.4387217,3.9115903 16.0563421,4.18328841 16.468089,4.72668464 C16.840622,5.21185984 17.0366919,5.90080863 17.0562989,6.77412399 L13.0564716,6.77412399 C13.0956856,7.33692722 13.242738,7.77358491 13.517236,8.08409704 C13.7917339,8.39460916 14.1740704,8.54986523 14.6544418,8.54986523 C15.0661888,8.54986523 15.4093112,8.44312668 15.6642022,8.2393531 C15.8798791,8.06469003 16.0465386,7.80269542 16.1739841,7.45336927 L16.958264,7.45336927 C16.840622,7.93854447 16.6151415,8.32668464 16.2720191,8.63719677 C15.8504686,9.00592992 15.3112762,9.2 14.6544418,9.2 C13.9289829,9.2 13.340773,8.9574124 12.9094191,8.4916442 C12.4584582,8.006469 12.2427812,7.36603774 12.2427812,6.5509434 C12.2427812,5.81347709 12.4486547,5.19245283 12.8800086,4.69757412 C13.3113625,4.17358491 13.8897689,3.9115903 14.6250313,3.9115903 Z M14.6446383,4.56172507 C14.1936774,4.56172507 13.8309479,4.70727763 13.55645,4.99838275 C13.281952,5.28948787 13.1250961,5.67762803 13.0760786,6.17250674 L16.2426086,6.17250674 C16.1445736,5.09541779 15.6053812,4.56172507 14.6446383,4.56172507 Z M19.3307106,2.42695418 L19.3307106,4.04743935 L20.5855584,4.04743935 L20.5855584,4.69757412 L19.3307106,4.69757412 L19.3307106,7.89002695 C19.3307106,8.07439353 19.3601211,8.21024259 19.4385491,8.28787062 C19.5071736,8.36549865 19.634619,8.41401617 19.811082,8.41401617 L20.4581129,8.41401617 L20.4581129,9.06415094 L19.69344,9.06415094 C19.2816931,9.06415094 18.9777846,8.9574124 18.8013217,8.74393531 C18.6346622,8.54986523 18.5562342,8.26846361 18.5562342,7.89002695 L18.5562342,4.69757412 L17.5366704,4.69757412 L17.5366704,4.04743935 L18.5562342,4.04743935 L18.5562342,2.74716981 L19.3307106,2.42695418 Z M23.6638569,3.9115903 C24.3893158,3.9115903 24.9187047,4.09595687 25.2716307,4.47439353 C25.5657356,4.80431267 25.7225916,5.26037736 25.7225916,5.8425876 L25.7225916,9.06415094 L24.9873292,9.06415094 L24.9873292,8.21994609 C24.7912592,8.4916442 24.5265648,8.7245283 24.2030493,8.89919137 C23.8305164,9.09326146 23.408966,9.2 22.9482015,9.2 C22.4384196,9.2 22.0266727,9.06415094 21.7325677,8.81185984 C21.4188558,8.54986523 21.2619998,8.20053908 21.2619998,7.7541779 C21.2619998,7.11374663 21.5168907,6.64797844 22.0364762,6.35687332 C22.4482231,6.11428571 23.016826,5.98814016 23.7226779,5.98814016 L24.9383117,5.97843666 L24.9383117,5.81347709 C24.9383117,4.96927224 24.4971543,4.55202156 23.6148394,4.55202156 C23.212896,4.55202156 22.8893805,4.6296496 22.6540966,4.80431267 C22.3992056,4.97897574 22.2423496,5.23126685 22.1835286,5.58059299 L21.4090523,5.58059299 C21.4874803,5.00808625 21.7325677,4.58113208 22.1541181,4.29973046 C22.5266511,4.03773585 23.0266295,3.9115903 23.6638569,3.9115903 Z M24.9383117,6.58975741 L23.7716954,6.59946092 C22.6344896,6.59946092 22.0658867,6.98760108 22.0658867,7.74447439 C22.0658867,7.98706199 22.1541181,8.19083558 22.3403846,8.34609164 C22.5266511,8.4916442 22.7815421,8.56927224 23.114861,8.56927224 C23.6246429,8.56927224 24.0559969,8.41401617 24.4187263,8.10350404 C24.7618487,7.79299191 24.9383117,7.43396226 24.9383117,7.02641509 L24.9383117,6.58975741 Z" fill="#FFFFFF"></path></g></svg></span><a class="_3Sn1bM ant-dropdown-trigger" href="https://www.jianshu.com/u/d01b8042d237"><img class="_3INfum" src="./聊聊Linux 五种IO模型 - 简书_files/76da8667-3674-4427-a757-1ccc99e442a4.jpeg" alt=""><i aria-label="icon: caret-down" class="anticon anticon-caret-down"><svg viewBox="0 0 1024 1024" focusable="false" class="" data-icon="caret-down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"></path></svg></i></a><a href="https://www.jianshu.com/writer" target="_blank" class="_1OyPqC _3Mi9q9 _2WY0RL _1YbC5u" role="button" tabindex="-1"><i aria-label="ic-write" style="margin-right:2px" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-write"></use></svg></i><span>写文章</span></a></div><div class="_1YyUun"><div class="_2RZATq"><nav class="_3JYrtj"><a class="hM7XFL _1OhGeD" href="https://www.jianshu.com/">发现</a><a class="hM7XFL _1OhGeD" href="https://www.jianshu.com/subscriptions">关注</a><a class="hM7XFL _1OhGeD" href="https://www.jianshu.com/vips">会员</a><a class="hM7XFL _1OhGeD" href="https://www.jianshu.com/techareas">IT技术</a><a class="hM7XFL ant-dropdown-trigger _1OhGeD" href="https://www.jianshu.com/notifications">消息</a></nav><div class="MoRCpo"><div class="_31TNvD"><input type="search" class="_2q13cl G1b3UE" value="" placeholder="搜索" aria-label="搜索专题"><span class="x6-7Eb" role="button" tabindex="-1" aria-label="搜索"><i aria-label="icon: search" class="anticon anticon-search"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0 0 11.6 0l43.6-43.5a8.2 8.2 0 0 0 0-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"></path></svg></i></span></div></div></div></div></div><div class="_3t3lfz"><div class="FTZkZo"><div class="_16zCst"><h1 class="_2zeTMs" title="聊聊Linux 五种IO模型">聊聊Linux 五种IO模型</h1></div><div class="_26qd_C"><a class="qzhJKO" href="https://www.jianshu.com/u/657c611b2e07"><img class="_2JlnTn" src="./聊聊Linux 五种IO模型 - 简书_files/404b7397-cbe2-40cf-8f36-6c8d019c9788.jpeg" alt=""><span class="_22gUMi">七寸知架构</span></a><button data-locale="zh-CN" type="button" class="_1OyPqC _3Mi9q9 ZccRSO"><span>已关注</span></button><button type="button" class="_1OyPqC _3Mi9q9 _1YbC5u"><span>赞赏支持</span></button></div></div></div></div><div class="VYwngI"></div></header><div class="_21bLU4 _3kbg6I"><div class="_3VRLsv" role="main"><div class="_gp-ck"><section class="ouvJEz"><div class="adad_container"><script type="text/javascript" src="https://www.jianshu.com/p/486b0965c296"></script></div><h1 class="_1RuRku">聊聊Linux 五种IO模型</h1><div class="rEsl9f"><div class="_2mYfmT"><a class="_1qp91i _1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" target="_blank" rel="noopener noreferrer"><img class="_13D2Eh" src="./聊聊Linux 五种IO模型 - 简书_files/404b7397-cbe2-40cf-8f36-6c8d019c9788(1).jpeg" alt=""></a><div style="margin-left: 8px;"><div class="_3U4Smb"><span class="FxYr8x"><a class="_1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" target="_blank" rel="noopener noreferrer">七寸知架构</a></span><button data-locale="zh-CN" type="button" class="_3kba3h _1OyPqC _3Mi9q9 _34692- ZccRSO"><span>已关注</span></button><span class="_3URWaO">IP属地: 云南</span></div><div class="s-dsoj"><span class="_3tCVn5"><i aria-label="ic-diamond" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-diamond"></use></svg></i><span>19</span></span><time datetime="2016-05-18T00:15:19.000Z">2016.05.18 08:15:19</time><span>字数 8,006</span><span>阅读 139,757</span></div></div></div></div><article class="_2rhmJa"><div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 354px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 18.34%;"></div>
<div class="image-view" data-width="1930" data-height="354"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png" data-original-width="1930" data-original-height="354" data-original-format="image/png" data-original-filesize="281105" data-image-index="0" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-6c2577a9facdef48.png"></div>
</div>
<div class="image-caption">个人主页，扫码关注</div>
</div>
<p>上一篇<a href="https://www.jianshu.com/p/aed6067eeac9" target="_blank">《聊聊同步、异步、阻塞与非阻塞》</a>已经通俗的讲解了，要理解同步、异步、阻塞与非阻塞重要的两个概念点了，没有看过的，建议先看这篇博文理解这两个概念点。在认知上，建立统一的模型。这样，大家在继续看本篇时，才不会理解有偏差。</p>
<p>那么，在正式开始讲Linux IO模型前，比如：同步IO和异步IO，阻塞IO和非阻塞IO分别是什么，到底有什么区别？不同的人在不同的上下文下给出的答案是不同的。所以先限定一下本文的上下文。</p>
<h1>1 概念说明</h1>
<p>在进行解释之前，首先要说明几个概念：</p>
<blockquote>
<p>用户空间和内核空间</p>
<p>进程切换</p>
<p>进程的阻塞</p>
<p>文件描述符</p>
<p>缓存 IO</p>
</blockquote>
<h2>1.1 用户空间与内核空间</h2>
<p>现在操作系统都是采用虚拟存储器，那么对32位操作系统而言，它的寻址空间（虚拟存储空间）为4G（2的32次方）。<code>操作系统的核心是内核，独立于普通的应用程序，可以访问受保护的内存空间，也有访问底层硬件设备的所有权限</code>。为了保证用户进程不能直接操作内核（kernel），保证内核的安全，<code>操作系统将虚拟空间划分为两部分，一部分为内核空间，一部分为用户空间</code>。针对linux操作系统而言，将最高的1G字节（从虚拟地址0xC0000000到0xFFFFFFFF），供内核使用，称为内核空间，而将较低的3G字节（从虚拟地址0x00000000到0xBFFFFFFF），供各个进程使用，称为用户空间。</p>
<h2>1.2 进程切换</h2>
<p>为了控制进程的执行，内核必须有能力挂起正在CPU上运行的进程，并恢复以前挂起的某个进程的执行。这种行为被称为进程切换。因此可以说，任何进程都是在操作系统内核的支持下运行的，是与内核紧密相关的。</p>
<p>从一个进程的运行转到另一个进程上运行，这个过程中经过下面这些变化：</p>
<blockquote>
<ol>
<li><p>保存处理机上下文，包括程序计数器和其他寄存器。</p></li>
<li><p>更新PCB信息。</p></li>
<li><p>把进程的PCB移入相应的队列，如就绪、在某事件阻塞等队列。</p></li>
<li><p>选择另一个进程执行，并更新其PCB。</p></li>
<li><p>更新内存管理的数据结构。</p></li>
<li><p>恢复处理机上下文。</p></li>
</ol>
</blockquote>
<p>注：总而言之就是很耗资源，具体的可以参考这篇文章：<a href="https://links.jianshu.com/go?to=http%3A%2F%2Fguojing.me%2Flinux-kernel-architecture%2Fposts%2Fprocess-switch%2F" target="_blank">进程切换</a>。</p>
<h2>1.3 进程的阻塞</h2>
<p>正在执行的进程，由于期待的某些事件未发生，如请求系统资源失败、等待某种操作的完成、新数据尚未到达或无新工作做等，则由系统自动执行阻塞原语(Block)，使自己由运行状态变为阻塞状态。可见，进程的阻塞是进程自身的一种主动行为，也因此只有处于运行态的进程（获得CPU），才可能将其转为阻塞状态。<code>当进程进入阻塞状态，是不占用CPU资源的</code>。</p>
<h2>1.4 文件描述符fd</h2>
<p>文件描述符（File descriptor）是计算机科学中的一个术语，<code>是一个用于表述指向文件的引用的抽象化概念</code>。</p>
<p>文件描述符在形式上是一个非负整数。实际上，<code>它是一个索引值，指向内核为每一个进程所维护的该进程打开文件的记录表</code>。当程序打开一个现有文件或者创建一个新文件时，内核向进程返回一个文件描述符。在程序设计中，一些涉及底层的程序编写往往会围绕着文件描述符展开。但是文件描述符这一概念往往只适用于UNIX、Linux这样的操作系统。</p>
<h2>1.5 缓存 IO</h2>
<p><code>缓存 IO 又被称作标准 IO，大多数文件系统的默认 IO 操作都是缓存 IO</code>。在 Linux 的缓存 IO 机制中，操作系统会将 IO 的数据缓存在文件系统的页缓存（ page cache ）中，也就是说，<code>数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间</code>。</p>
<p><strong>缓存 IO 的缺点：</strong></p>
<p><code>数据在传输过程中需要在应用程序地址空间和内核进行多次数据拷贝操作</code>，这些数据拷贝操作所带来的 CPU 以及内存开销是非常大的。</p>
<h1>2 Linux IO模型</h1>
<p><code>网络IO的本质是socket的读取，socket在linux系统被抽象为流，IO可以理解为对流的操作</code>。刚才说了，对于一次IO访问（以read举例），<code>数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间</code>。所以说，当一个read操作发生时，它会经历两个阶段：</p>
<blockquote>
<ol>
<li><p>第一阶段：等待数据准备 (Waiting for the data to be ready)。</p></li>
<li><p>第二阶段：将数据从内核拷贝到进程中 (Copying the data from the kernel to the process)。</p></li>
</ol>
</blockquote>
<p>对于socket流而言，</p>
<blockquote>
<ol>
<li><p>第一步：通常涉及等待网络上的数据分组到达，然后被复制到内核的某个缓冲区。</p></li>
<li><p>第二步：把数据从内核缓冲区复制到应用进程缓冲区。</p></li>
</ol>
</blockquote>
<p>网络应用需要处理的无非就是两大类问题，<code>网络IO，数据计算</code>。相对于后者，网络IO的延迟，给应用带来的性能瓶颈大于后者。网络IO的模型大致有如下几种：</p>
<blockquote>
<ul>
<li><p><strong>同步模型（synchronous IO）</strong></p></li>
<li><p>阻塞IO（bloking IO）</p></li>
<li><p>非阻塞IO（non-blocking IO）</p></li>
<li><p>多路复用IO（multiplexing IO）</p></li>
<li><p>信号驱动式IO（signal-driven IO）</p></li>
<li><p><strong>异步IO（asynchronous IO）</strong></p></li>
</ul>
</blockquote>
<p><strong><code>注：由于signal driven IO在实际中并不常用，所以我这只提及剩下的四种IO Model。</code></strong></p>
<p>在深入介绍Linux IO各种模型之前，让我们先来探索一下基本 Linux IO 模型的简单矩阵。如下图所示：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 460px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 58.52%;"></div>
<div class="image-view" data-width="786" data-height="460"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-49ac9eb7d4d2d019.png" data-original-width="786" data-original-height="460" data-original-format="image/png" data-original-filesize="46987" data-image-index="1" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-49ac9eb7d4d2d019.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<p>每个 IO 模型都有自己的使用模式，它们对于特定的应用程序都有自己的优点。本节将简要对其一一进行介绍。<code>常见的IO模型有阻塞、非阻塞、IO多路复用，异步</code>。以一个生动形象的例子来说明这四个概念。周末我和女友去逛街，中午饿了，我们准备去吃饭。周末人多，吃饭需要排队，我和女友有以下几种方案。</p>
<h2>2.1 同步阻塞 IO（blocking IO）</h2>
<h3>2.1.1 场景描述</h3>
<blockquote>
<p>我和女友点完餐后，不知道什么时候能做好，只好坐在餐厅里面等，直到做好，然后吃完才离开。女友本想还和我一起逛街的，但是不知道饭能什么时候做好，只好和我一起在餐厅等，而不能去逛街，直到吃完饭才能去逛街，中间等待做饭的时间浪费掉了。<code>这就是典型的阻塞</code>。</p>
</blockquote>
<h3>2.1.2 网络模型</h3>
<p><code>同步阻塞 IO 模型是最常用的一个模型，也是最简单的模型</code>。在linux中，<code>默认情况下所有的socket都是blocking</code>。它符合人们最常见的思考逻辑。<code>阻塞就是进程 "被" 休息, CPU处理其它进程去了</code>。</p>
<p>在这个IO模型中，用户空间的应用程序执行一个系统调用（recvform），这会导致应用程序阻塞，什么也不干，直到数据准备好，并且将数据从内核复制到用户进程，最后进程再处理数据，<code>在等待数据到处理数据的两个阶段</code>，整个进程都被阻塞。不能处理别的网络IO。<code>调用应用程序处于一种不再消费 CPU 而只是简单等待响应的状态</code>，因此从处理的角度来看，这是非常有效的。在调用recv()/recvfrom()函数时，发生在内核中等待数据和复制数据的过程，大致如下图：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 646px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 54.559999999999995%;"></div>
<div class="image-view" data-width="1184" data-height="646"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-41550941d72be698.png" data-original-width="1184" data-original-height="646" data-original-format="image/png" data-original-filesize="183722" data-image-index="2" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-41550941d72be698.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<h3>2.1.3 流程描述</h3>
<p>当用户进程调用了recv()/recvfrom()这个系统调用，<code>kernel就开始了IO的第一个阶段：准备数据</code>（对于网络IO来说，很多时候数据在一开始还没有到达。比如，还没有收到一个完整的UDP包。这个时候kernel就要等待足够的数据到来）。这个过程需要等待，也就是说数据被拷贝到操作系统内核的缓冲区中是需要一个过程的。而在用户进程这边，整个进程会被阻塞（当然，是进程自己选择的阻塞）。<code>第二个阶段：当kernel一直等到数据准备好了，它就会将数据从kernel中拷贝到用户内存</code>，然后kernel返回结果，用户进程才解除block的状态，重新运行起来。</p>
<blockquote>
<p>所以，blocking IO的特点就是在IO执行的两个阶段都被block了。</p>
</blockquote>
<p><strong>优点：</strong></p>
<blockquote>
<ol>
<li><p>能够及时返回数据，无延迟；</p></li>
<li><p>对内核开发者来说这是省事了；</p></li>
</ol>
</blockquote>
<p><strong>缺点：</strong></p>
<blockquote>
<ol>
<li>对用户来说处于等待就要付出性能的代价了；</li>
</ol>
</blockquote>
<h2>2.2 同步非阻塞 IO（nonblocking IO）</h2>
<h3>2.2.1 场景描述</h3>
<blockquote>
<p>我女友不甘心白白在这等，又想去逛商场，又担心饭好了。所以我们逛一会，回来询问服务员饭好了没有，来来回回好多次，饭都还没吃都快累死了啦。<code>这就是非阻塞</code>。需要不断的询问，是否准备好了。</p>
</blockquote>
<h3>2.2.2 网络模型</h3>
<p><code>同步非阻塞就是 “每隔一会儿瞄一眼进度条” 的轮询（polling）方式</code>。在这种模型中，<code>设备是以非阻塞的形式打开的</code>。这意味着 IO 操作不会立即完成，read 操作可能会返回一个错误代码，说明这个命令不能立即满足（EAGAIN 或 EWOULDBLOCK）。</p>
<p>在网络IO时候，非阻塞IO也会进行recvform系统调用，检查数据是否准备好，与阻塞IO不一样，"非阻塞将大的整片时间的阻塞分成N多的小的阻塞, 所以进程不断地有机会 '被' CPU光顾"。</p>
<p><code>也就是说非阻塞的recvform系统调用调用之后，进程并没有被阻塞，内核马上返回给进程，如果数据还没准备好，此时会返回一个error</code>。进程在返回之后，可以干点别的事情，然后再发起recvform系统调用。重复上面的过程，循环往复的进行recvform系统调用。<code>这个过程通常被称之为轮询</code>。轮询检查内核数据，直到数据准备好，再拷贝数据到进程，进行数据处理。<strong><code>需要注意，拷贝数据整个过程，进程仍然是属于阻塞的状态</code></strong>。</p>
<p>在linux下，可以通过设置socket使其变为non-blocking。<code>当对一个non-blocking socket执行读操作时</code>，流程如图所示：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 638px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 54.620000000000005%;"></div>
<div class="image-view" data-width="1168" data-height="638"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-69746d536c2781da.png" data-original-width="1168" data-original-height="638" data-original-format="image/png" data-original-filesize="262569" data-image-index="3" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-69746d536c2781da.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<h3>2.2.3 流程描述</h3>
<p>当用户进程发出read操作时，如果kernel中的数据还没有准备好，那么它并不会block用户进程，而是立刻返回一个error。从用户进程角度讲，它发起一个read操作后，并不需要等待，而是马上就得到了一个结果。用户进程判断结果是一个error时，它就知道数据还没有准备好，于是它可以再次发送read操作。一旦kernel中的数据准备好了，并且又再次收到了用户进程的system call，那么它马上就将数据拷贝到了用户内存，然后返回。</p>
<blockquote>
<p>所以，nonblocking IO的特点是用户进程需要不断的主动询问kernel数据好了没有。</p>
</blockquote>
<p><strong>同步非阻塞方式相比同步阻塞方式：</strong></p>
<blockquote>
<p>优点：能够在等待任务完成的时间里干其他活了（包括提交其他任务，也就是 “后台” 可以有多个任务在同时执行）。</p>
<p>缺点：任务完成的响应延迟增大了，因为每过一段时间才去轮询一次read操作，而任务可能在两次轮询之间的任意时间完成。这会导致整体数据吞吐量的降低。</p>
</blockquote>
<h2>2.3 IO 多路复用（ IO multiplexing）</h2>
<h3>2.3.1 场景描述</h3>
<blockquote>
<p>与第二个方案差不多，餐厅安装了电子屏幕用来显示点餐的状态，这样我和女友逛街一会，回来就不用去询问服务员了，直接看电子屏幕就可以了。这样每个人的餐是否好了，都直接看电子屏幕就可以了，<code>这就是典型的IO多路复用</code>。</p>
</blockquote>
<h3>2.3.2 网络模型</h3>
<p>由于同步非阻塞方式需要不断主动轮询，轮询占据了很大一部分过程，轮询会消耗大量的CPU时间，而 “后台” 可能有多个任务在同时进行，人们就想到了循环查询多个任务的完成状态，只要有任何一个任务完成，就去处理它。如果轮询不是进程的用户态，而是有人帮忙就好了。<code>那么这就是所谓的 “IO 多路复用”</code>。UNIX/Linux 下的 select、poll、epoll 就是干这个的（epoll 比 poll、select 效率高，做的事情是一样的）。</p>
<p><code>IO多路复用有两个特别的系统调用select、poll、epoll函数</code>。select调用是内核级别的，select轮询相对非阻塞的轮询的区别在于---<code>前者可以等待多个socket，能实现同时对多个IO端口进行监听</code>，当其中任何一个socket的数据准好了，<code>就能返回进行可读</code>，<code>然后进程再进行recvform系统调用，将数据由内核拷贝到用户进程，当然这个过程是阻塞的</code>。select或poll调用之后，会阻塞进程，与blocking IO阻塞不同在于，<code>此时的select不是等到socket数据全部到达再处理, 而是有了一部分数据就会调用用户进程来处理</code>。如何知道有一部分数据到达了呢？<code>监视的事情交给了内核，内核负责数据到达的处理。也可以理解为"非阻塞"吧</code>。</p>
<p><code>I/O复用模型会用到select、poll、epoll函数，这几个函数也会使进程阻塞，但是和阻塞I/O所不同的的，这两个函数可以同时阻塞多个I/O操作</code>。而且可以同时对多个读操作，多个写操作的I/O函数进行检测，直到有数据可读或可写时（注意不是全部数据可读或可写），才真正调用I/O操作函数。</p>
<p>对于多路复用，也就是轮询多个socket。<code>多路复用既然可以处理多个IO，也就带来了新的问题，多个IO之间的顺序变得不确定了</code>，当然也可以针对不同的编号。具体流程，如下图所示：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 588px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 52.129999999999995%;"></div>
<div class="image-view" data-width="1128" data-height="588"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-d552e1e2ca381a08.png" data-original-width="1128" data-original-height="588" data-original-format="image/png" data-original-filesize="246096" data-image-index="4" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-d552e1e2ca381a08.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<h3>2.3.3 流程描述</h3>
<p>IO multiplexing就是我们说的select，poll，epoll，有些地方也称这种IO方式为event driven IO。<code>select/epoll的好处就在于单个process就可以同时处理多个网络连接的IO</code>。它的基本原理就是select，poll，epoll这个function会不断的轮询所负责的所有socket，当某个socket有数据到达了，就通知用户进程。</p>
<p><code>当用户进程调用了select，那么整个进程会被block</code>，而同时，kernel会“监视”所有select负责的socket，<code>当任何一个socket中的数据准备好了，select就会返回</code>。这个时候用户进程再调用read操作，将数据从kernel拷贝到用户进程。</p>
<blockquote>
<p>多路复用的特点是<code>通过一种机制一个进程能同时等待IO文件描述符</code>，内核监视这些文件描述符（套接字描述符），其中的任意一个进入读就绪状态，select， poll，epoll函数就可以返回。对于监视的方式，又可以分为 select， poll， epoll三种方式。</p>
</blockquote>
<p>上面的图和blocking IO的图其实并没有太大的不同，事实上，还更差一些。<code>因为这里需要使用两个system call (select 和 recvfrom)，而blocking IO只调用了一个system call (recvfrom)</code>。但是，<code>用select的优势在于它可以同时处理多个connection</code>。</p>
<p>所以，如果处理的连接数不是很高的话，使用select/epoll的web server不一定比使用multi-threading + blocking IO的web server性能更好，可能延迟还更大。（select/epoll的优势并不是对于单个连接能处理得更快，而是在于能处理更多的连接。）</p>
<p>在IO multiplexing Model中，<code>实际中，对于每一个socket，一般都设置成为non-blocking</code>，但是，如上图所示，整个用户的process其实是一直被block的。<code>只不过process是被select这个函数block，而不是被socket IO给block</code>。所以<strong><code>IO多路复用是阻塞在select，epoll这样的系统调用之上，而没有阻塞在真正的I/O系统调用如recvfrom之上。</code></strong></p>
<p>在I/O编程过程中，<code>当需要同时处理多个客户端接入请求时，可以利用多线程或者I/O多路复用技术进行处理</code>。I/O多路复用技术<code>通过把多个I/O的阻塞复用到同一个select的阻塞上，从而使得系统在单线程的情况下可以同时处理多个客户端请求</code>。与传统的多线程/多进程模型比，<code>I/O多路复用的最大优势是系统开销小</code>，系统不需要创建新的额外进程或者线程，也不需要维护这些进程和线程的运行，降底了系统的维护工作量，节省了系统资源，I/O多路复用的主要应用场景如下：</p>
<blockquote>
<p>服务器需要同时处理多个处于监听状态或者多个连接状态的套接字。</p>
<p>服务器需要同时处理多种网络协议的套接字。</p>
</blockquote>
<p>了解了前面三种IO模式，在用户进程进行系统调用的时候，<strong><code>他们在等待数据到来的时候，处理的方式不一样，直接等待，轮询，select或poll轮询</code></strong>，两个阶段过程：</p>
<blockquote>
<p>第一个阶段有的阻塞，有的不阻塞，有的可以阻塞又可以不阻塞。</p>
<p>第二个阶段都是阻塞的。</p>
</blockquote>
<p><strong><code>从整个IO过程来看，他们都是顺序执行的，因此可以归为同步模型(synchronous)。都是进程主动等待且向内核检查状态。【此句很重要！！！】</code></strong></p>
<p><code>高并发的程序一般使用同步非阻塞方式而非多线程 + 同步阻塞方式</code>。要理解这一点，首先要扯到并发和并行的区别。比如去某部门办事需要依次去几个窗口，<code>办事大厅里的人数就是并发数，而窗口个数就是并行度</code>。也就是说<code>并发数是指同时进行的任务数（如同时服务的 HTTP 请求）</code>，而<code>并行数是可以同时工作的物理资源数量（如 CPU 核数）</code>。通过合理调度任务的不同阶段，并发数可以远远大于并行度，这就是区区几个 CPU 可以支持上万个用户并发请求的奥秘。在这种高并发的情况下，为每个任务（用户请求）创建一个进程或线程的开销非常大。<code>而同步非阻塞方式可以把多个 IO 请求丢到后台去，这就可以在一个进程里服务大量的并发 IO 请求</code>。</p>
<p><strong>注意：IO多路复用是同步阻塞模型还是异步阻塞模型，在此给大家分析下：</strong></p>
<blockquote>
<p>此处仍然不太清楚的，强烈建议大家在细究<a href="https://links.jianshu.com/go?to=http%3A%2F%2Fmy.oschina.net%2Fxianggao%2Fblog%2F661085" target="_blank">《聊聊同步、异步、阻塞与非阻塞》</a>中讲同步与异步的根本性区别，<code>同步是需要主动等待消息通知，而异步则是被动接收消息通知，通过回调、通知、状态等方式来被动获取消息</code>。<code>IO多路复用在阻塞到select阶段时，用户进程是主动等待并调用select函数获取数据就绪状态消息，并且其进程状态为阻塞</code>。所以，<code>把IO多路复用归为同步阻塞模式</code>。</p>
</blockquote>
<h2>2.4 信号驱动式IO（signal-driven IO）</h2>
<p>信号驱动式I/O：首先我们允许Socket进行信号驱动IO,并安装一个信号处理函数，进程继续运行并不阻塞。当数据准备好时，进程会收到一个SIGIO信号，可以在信号处理函数中调用I/O操作函数处理数据。过程如下图所示：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 446px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 63.59%;"></div>
<div class="image-view" data-width="1192" data-height="758"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-222408c76186fd8c.png" data-original-width="1192" data-original-height="758" data-original-format="image/png" data-original-filesize="210403" data-image-index="5" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-222408c76186fd8c.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<h2>2.5 异步非阻塞 IO（asynchronous IO）</h2>
<h3>2.5.1 场景描述</h3>
<blockquote>
<p>女友不想逛街，又餐厅太吵了，回家好好休息一下。于是我们叫外卖，打个电话点餐，然后我和女友可以在家好好休息一下，饭好了送货员送到家里来。这就是典型的异步，只需要打个电话说一下，然后可以做自己的事情，饭好了就送来了。</p>
</blockquote>
<h3>2.5.2 网络模型</h3>
<p>相对于同步IO，异步IO不是顺序执行。<code>用户进程进行aio_read系统调用之后，无论内核数据是否准备好，都会直接返回给用户进程，然后用户态进程可以去做别的事情</code>。等到socket数据准备好了，内核直接复制数据给进程，<code>然后从内核向进程发送通知</code>。<code>IO两个阶段，进程都是非阻塞的</code>。</p>
<p>Linux提供了AIO库函数实现异步，但是用的很少。目前有很多开源的异步IO库，例如libevent、libev、libuv。异步过程如下图所示：</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 441px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 62.93%;"></div>
<div class="image-view" data-width="1176" data-height="740"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-5283bdc9d033e956.png" data-original-width="1176" data-original-height="740" data-original-format="image/png" data-original-filesize="182023" data-image-index="6" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-5283bdc9d033e956.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<h3>2.5.3 流程描述</h3>
<p>用户进程发起aio_read操作之后，立刻就可以开始去做其它的事。而另一方面，从kernel的角度，当它受到一个asynchronous read之后，<code>首先它会立刻返回，所以不会对用户进程产生任何block</code>。然后，kernel会等待数据准备完成，然后将数据拷贝到用户内存，<code>当这一切都完成之后，kernel会给用户进程发送一个signal或执行一个基于线程的回调函数来完成这次 IO 处理过程</code>，告诉它read操作完成了。</p>
<p><strong>在 Linux 中，通知的方式是 “信号”：</strong></p>
<blockquote>
<p><code>如果这个进程正在用户态忙着做别的事（例如在计算两个矩阵的乘积），那就强行打断之，调用事先注册的信号处理函数</code>，这个函数可以决定何时以及如何处理这个异步任务。由于信号处理函数是突然闯进来的，因此跟中断处理程序一样，有很多事情是不能做的，因此保险起见，<code>一般是把事件 “登记” 一下放进队列，然后返回该进程原来在做的事</code>。</p>
<p><code>如果这个进程正在内核态忙着做别的事</code>，例如以同步阻塞方式读写磁盘，<code>那就只好把这个通知挂起来了，等到内核态的事情忙完了，快要回到用户态的时候，再触发信号通知</code>。</p>
<p><code>如果这个进程现在被挂起了，例如无事可做 sleep 了，那就把这个进程唤醒</code>，下次有 CPU 空闲的时候，就会调度到这个进程，触发信号通知。</p>
</blockquote>
<p>异步 API 说来轻巧，做来难，这主要是对 API 的实现者而言的。Linux 的异步 IO（AIO）支持是 2.6.22 才引入的，还有很多系统调用不支持异步 IO。Linux 的异步 IO 最初是为数据库设计的，<code>因此通过异步 IO 的读写操作不会被缓存或缓冲，这就无法利用操作系统的缓存与缓冲机制</code>。</p>
<p><strong><code>很多人把 Linux 的 O_NONBLOCK 认为是异步方式，但事实上这是前面讲的同步非阻塞方式。</code></strong>需要指出的是，虽然 Linux 上的 IO API 略显粗糙，但每种编程框架都有封装好的异步 IO 实现。操作系统少做事，把更多的自由留给用户，正是 UNIX 的设计哲学，也是 Linux 上编程框架百花齐放的一个原因。</p>
<p>从前面 IO 模型的分类中，我们可以看出 AIO 的动机：</p>
<blockquote>
<p>同步阻塞模型需要在 IO 操作开始时阻塞应用程序。这意味着不可能同时重叠进行处理和 IO 操作。</p>
<p>同步非阻塞模型允许处理和 IO 操作重叠进行，但是这需要应用程序根据重现的规则来检查 IO 操作的状态。</p>
<p>这样就剩下异步非阻塞 IO 了，它允许处理和 IO 操作重叠进行，包括 IO 操作完成的通知。</p>
</blockquote>
<p>IO多路复用除了需要阻塞之外，<code>select 函数所提供的功能（异步阻塞 IO）与 AIO 类似</code>。不过，<code>它是对通知事件进行阻塞，而不是对 IO 调用进行阻塞</code>。</p>
<h2>2.6 关于异步阻塞</h2>
<p>有时我们的 API 只提供异步通知方式，例如在 node.js 里，<code>但业务逻辑需要的是做完一件事后做另一件事</code>，例如数据库连接初始化后才能开始接受用户的 HTTP 请求。<code>这样的业务逻辑就需要调用者是以阻塞方式来工作</code>。</p>
<p><code>为了在异步环境里模拟 “顺序执行” 的效果，就需要把同步代码转换成异步形式，这称为 CPS（Continuation Passing Style）变换</code>。BYVoid 大神的 <a href="https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2FBYVoid%2Fcontinuation" target="_blank">continuation.js</a> 库就是一个 CPS 变换的工具。<code>用户只需用比较符合人类常理的同步方式书写代码，CPS 变换器会把它转换成层层嵌套的异步回调形式</code>。</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 684px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 63.22%;"></div>
<div class="image-view" data-width="1082" data-height="684"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-0d7cf290f0c4b88c.png" data-original-width="1082" data-original-height="684" data-original-format="image/png" data-original-filesize="295152" data-image-index="7" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-0d7cf290f0c4b88c.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 489px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 69.83%;"></div>
<div class="image-view" data-width="1266" data-height="884"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-199172d7d0ae818d.png" data-original-width="1266" data-original-height="884" data-original-format="image/png" data-original-filesize="385584" data-image-index="8" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-199172d7d0ae818d.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<p><code>另外一种使用阻塞方式的理由是降低响应延迟</code>。如果采用非阻塞方式，一个任务 A 被提交到后台，就开始做另一件事 B，但 B 还没做完，A 就完成了，这时要想让 A 的完成事件被尽快处理（比如 A 是个紧急事务），要么丢弃做到一半的 B，要么保存 B 的中间状态并切换回 A，任务的切换是需要时间的（不管是从磁盘载入到内存，还是从内存载入到高速缓存），这势必降低 A 的响应速度。<code>因此，对实时系统或者延迟敏感的事务，有时采用阻塞方式比非阻塞方式更好</code>。</p>
<h1>3 五种IO模型总结</h1>
<h2>3.1 blocking和non-blocking区别</h2>
<p>调用blocking IO会一直block住对应的进程直到操作完成，而non-blocking IO在kernel还准备数据的情况下会立刻返回。</p>
<h2>3.2 synchronous IO和asynchronous IO区别</h2>
<p>在说明synchronous IO和asynchronous IO的区别之前，需要先给出两者的定义。POSIX的定义是这样子的：</p>
<blockquote>
<p>A synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes;</p>
<p>An asynchronous I/O operation does not cause the requesting process to be blocked;</p>
</blockquote>
<p><code>两者的区别就在于synchronous IO做”IO operation”的时候会将process阻塞</code>。按照这个定义，之前所述的blocking IO，non-blocking IO，IO multiplexing都属于synchronous IO。</p>
<p>有人会说，non-blocking IO并没有被block啊。这里有个非常“狡猾”的地方，<code>定义中所指的”IO operation”是指真实的IO操作</code>，就是例子中的recvfrom这个system call。non-blocking IO在执行recvfrom这个system call的时候，如果kernel的数据没有准备好，这时候不会block进程。但是，<code>当kernel中数据准备好的时候，recvfrom会将数据从kernel拷贝到用户内存中，这个时候进程是被block了</code>，在这段时间内，进程是被block的。</p>
<p>而asynchronous IO则不一样，<code>当进程发起IO 操作之后，就直接返回再也不理睬了，直到kernel发送一个信号，告诉进程说IO完成</code>。在这整个过程中，进程完全没有被block。</p>
<p><strong>各个IO Model的比较如图所示：</strong></p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 449px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 64.11%;"></div>
<div class="image-view" data-width="1276" data-height="818"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-a630f1d47b7ba148.png" data-original-width="1276" data-original-height="818" data-original-format="image/png" data-original-filesize="406467" data-image-index="9" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-a630f1d47b7ba148.png"></div>
</div>
<div class="image-caption">输入图片说明</div>
</div>
<p>通过上面的图片，可以发现non-blocking IO和asynchronous IO的区别还是很明显的。<code>在non-blocking IO中，虽然进程大部分时间都不会被block，但是它仍然要求进程去主动的check</code>，并且当数据准备完成以后，也需要进程主动的再次调用recvfrom来将数据拷贝到用户内存。而asynchronous IO则完全不同。<code>它就像是用户进程将整个IO操作交给了他人（kernel）完成，然后他人做完后发信号通知</code>。在此期间，<code>用户进程不需要去检查IO操作的状态，也不需要主动的去拷贝数据</code>。</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 354px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 18.34%;"></div>
<div class="image-view" data-width="1930" data-height="354"><img data-original-src="//upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png" data-original-width="1930" data-original-height="354" data-original-format="image/png" data-original-filesize="281105" data-image-index="10" style="cursor: zoom-in;" class="" src="./聊聊Linux 五种IO模型 - 简书_files/2062729-6c2577a9facdef48.png"></div>
</div>
<div class="image-caption">个人主页，扫码关注</div>
</div>
</article><div></div><div class="_3y7CB9"><div>最后编辑于 <!-- -->：<time datetime="2021-05-09T14:43:56.000Z">2021.05.09 22:43:56</time></div><div class="_2Kbacm">©<!-- -->著作权归作者所有,转载或内容合作请联系作者</div></div><div class="_1kCBjS"><div class="_18vaTa"><div class="_3BUZPB"><div class="_2Bo4Th _3Nksh7" role="button" tabindex="-1" aria-label="给文章点赞"><i aria-label="ic-like" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-like"></use></svg></i></div><span class="_1LOh_5" role="button" tabindex="-1" aria-label="查看点赞列表">445人点赞<i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></span></div><div class="_3BUZPB"><div class="_2Bo4Th" role="button" tabindex="-1"><i aria-label="ic-dislike" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-dislike"></use></svg></i></div></div></div><div class="_18vaTa"><a class="_3BUZPB _1x1ok9 _1OhGeD" href="https://www.jianshu.com/nb/4257867" target="_blank" rel="noopener noreferrer"><i aria-label="ic-notebook" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-notebook"></use></svg></i><span>40_聊聊远程通信</span></a><div class="_3BUZPB ant-dropdown-trigger"><div class="_2Bo4Th"><i aria-label="ic-others" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-others"></use></svg></i></div></div></div></div><div class="_19DgIp" style="margin-top:24px;margin-bottom:24px"></div><div class="_13lIbp"><div class="_16AzcO">更多精彩内容，就在简书APP</div><div class="_6S_NkV"><img src="./聊聊Linux 五种IO模型 - 简书_files/js-qrc.png" class="_25hm0R"></div><div class="l8ZVfE _3lGDiG"></div><div class="_191KSt">"赞赏我的文章给您带来收获"</div><button type="button" class="_1OyPqC _3Mi9q9 _2WY0RL _1YbC5u"><span>赞赏支持</span></button><div class="_1Segjj"><a class="H4XBOO _1OhGeD" href="https://www.jianshu.com/u/a7b34e552485" target="_blank" rel="noopener noreferrer"><img src="./聊聊Linux 五种IO模型 - 简书_files/9-cceda3cf5072bcdd77e8ca4f21c40998.jpg" alt="  "></a><a class="H4XBOO"><img src="./聊聊Linux 五种IO模型 - 简书_files/wechat-771371d5741b0c32cd805caeb48ad6c0.png" alt="  "></a><a class="H4XBOO"><img src="./聊聊Linux 五种IO模型 - 简书_files/wechat-771371d5741b0c32cd805caeb48ad6c0.png" alt="  "></a><a class="H4XBOO"><img src="./聊聊Linux 五种IO模型 - 简书_files/wechat-771371d5741b0c32cd805caeb48ad6c0.png" alt="  "></a><a class="H4XBOO"><img src="./聊聊Linux 五种IO模型 - 简书_files/0" alt="  "></a><span class="yZLjoN" role="button" tabindex="-1" aria-label="查看赞赏人列表">共5人赞赏</span></div></div><div class="d0hShY"><a class="_1bPVBH _1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" target="_blank" rel="noopener noreferrer"><img class="_27NmgV" src="./聊聊Linux 五种IO模型 - 简书_files/404b7397-cbe2-40cf-8f36-6c8d019c9788(2).jpeg" alt="  "></a><div class="Uz-vZq"><div class="Cqpr1X"><a class="HC3FFO _1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" title="七寸知架构" target="_blank" rel="noopener noreferrer">七寸知架构</a><span class="_2WEj6j" title="打蛇打七寸，架构悟认知，亦知海行舟，方悠然自得。">打蛇打七寸，架构悟认知，亦知海行舟，方悠然自得。</span></div><div class="lJvI3S"><span>总资产195</span><span>共写了63.3W字</span><span>获得13,334个赞</span><span>共7,872个粉丝</span></div></div><button data-locale="zh-CN" type="button" class="_1OyPqC _3Mi9q9 ZccRSO"><span>已关注</span></button></div></section><section class="ouvJEz"><ul class="_3eq_La"><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="人面猴" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/1003a129be45" target="_blank" rel="noopener noreferrer">人面猴</a></div><div class="_2GZFLj">序言：七十年代末，一起剥皮案震惊了整个滨河市，随后出现的几起案子，更是在滨河造成了极大的恐慌，老刑警刘岩，带你破解...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->201,468</span><span class="_3Q5ric">评论<!-- --> <!-- -->5</span><span class="_3Q5ric">赞<!-- --> <!-- -->473</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="死咒" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/1c4506f51019" target="_blank" rel="noopener noreferrer">死咒</a></div><div class="_2GZFLj">序言：滨河连续发生了三起死亡事件，死亡现场离奇诡异，居然都是意外死亡，警方通过查阅死者的电脑和手机，发现死者居然都...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->84,620</span><span class="_3Q5ric">评论<!-- --> <!-- -->2</span><span class="_3Q5ric">赞<!-- --> <!-- -->377</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="救了他两次的神仙让他今天三更去死" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/1ded57e57939" target="_blank" rel="noopener noreferrer">救了他两次的神仙让他今天三更去死</a></div><div class="_2GZFLj">文/潘晓璐 我一进店门，熙熙楼的掌柜王于贵愁眉苦脸地迎上来，“玉大人，你说我怎么就摊上这事。” “怎么了？”我有些...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->148,427</span><span class="_3Q5ric">评论<!-- --> <!-- -->0</span><span class="_3Q5ric">赞<!-- --> <!-- -->334</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="道士缉凶录：失踪的卖姜人" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/25685c1b1f2b" target="_blank" rel="noopener noreferrer">道士缉凶录：失踪的卖姜人</a></div><div class="_2GZFLj">   文/不坏的土叔    我叫张陵，是天一观的道长。 经常有香客问我，道长，这世上最难降的妖魔是什么？ 我笑而不...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->54,160</span><span class="_3Q5ric">评论<!-- --> <!-- -->1</span><span class="_3Q5ric">赞<!-- --> <!-- -->272</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="﻿港岛之恋（遗憾婚礼）" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/553802eff5d6" target="_blank" rel="noopener noreferrer">﻿港岛之恋（遗憾婚礼）</a></div><div class="_2GZFLj">正文 为了忘掉前任，我火速办了婚礼，结果婚礼上，老公的妹妹穿的比我还像新娘。我一直安慰自己，他们只是感情好，可当我...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/0f438ff0a55f" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg" alt=""><span class="cwEQzo">茶点故事</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->63,197</span><span class="_3Q5ric">评论<!-- --> <!-- -->5</span><span class="_3Q5ric">赞<!-- --> <!-- -->363</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="恶毒庶女顶嫁案：这布局不是一般人想出来的" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/59985a89b4ef" target="_blank" rel="noopener noreferrer">恶毒庶女顶嫁案：这布局不是一般人想出来的</a></div><div class="_2GZFLj">文/花漫 我一把揭开白布。 她就那样静静地躺着，像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上，一...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->48,334</span><span class="_3Q5ric">评论<!-- --> <!-- -->1</span><span class="_3Q5ric">赞<!-- --> <!-- -->281</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="城市分裂传说" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/62a01de427e0" target="_blank" rel="noopener noreferrer">城市分裂传说</a></div><div class="_2GZFLj">那天，我揣着相机与录音，去河边找鬼。 笑死，一个胖子当着我的面吹牛，可吹牛的内容都是我干的。 我是一名探鬼主播，决...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->37,775</span><span class="_3Q5ric">评论<!-- --> <!-- -->3</span><span class="_3Q5ric">赞<!-- --> <!-- -->393</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="双鸳鸯连环套：你想象不到人心有多黑" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/6ccdc163474a" target="_blank" rel="noopener noreferrer">双鸳鸯连环套：你想象不到人心有多黑</a></div><div class="_2GZFLj">文/苍兰香墨 我猛地睁开眼，长吁一口气：“原来是场噩梦啊……” “哼！你这毒妇竟也来了？” 一声冷哼从身侧响起，我...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->36,444</span><span class="_3Q5ric">评论<!-- --> <!-- -->0</span><span class="_3Q5ric">赞<!-- --> <!-- -->256</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="万荣杀人案实录" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/8796e3463067" target="_blank" rel="noopener noreferrer">万荣杀人案实录</a></div><div class="_2GZFLj">序言：老挝万荣一对情侣失踪，失踪者是张志新（化名）和其女友刘颖，没想到半个月后，有当地人在树林里发现了一具尸体，经...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->40,628</span><span class="_3Q5ric">评论<!-- --> <!-- -->1</span><span class="_3Q5ric">赞<!-- --> <!-- -->295</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="﻿护林员之死" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/8a691dd8fa34" target="_blank" rel="noopener noreferrer">﻿护林员之死</a></div><div class="_2GZFLj">正文 独居荒郊野岭守林人离奇死亡，尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/0f438ff0a55f" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg" alt=""><span class="cwEQzo">茶点故事</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->35,459</span><span class="_3Q5ric">评论<!-- --> <!-- -->2</span><span class="_3Q5ric">赞<!-- --> <!-- -->317</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="﻿白月光启示录" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/a5293fa3b5e0" target="_blank" rel="noopener noreferrer">﻿白月光启示录</a></div><div class="_2GZFLj">正文 我和宋清朗相恋三年，在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/0f438ff0a55f" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg" alt=""><span class="cwEQzo">茶点故事</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->37,508</span><span class="_3Q5ric">评论<!-- --> <!-- -->1</span><span class="_3Q5ric">赞<!-- --> <!-- -->329</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="活死人" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/a83aa7e71001" target="_blank" rel="noopener noreferrer">活死人</a></div><div class="_2GZFLj">序言：一个原本活蹦乱跳的男人离奇死亡，死状恐怖，灵堂内的尸体忽然破棺而出，到底是诈尸还是另有隐情，我是刑警宁泽，带...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->33,210</span><span class="_3Q5ric">评论<!-- --> <!-- -->3</span><span class="_3Q5ric">赞<!-- --> <!-- -->318</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="﻿日本核电站爆炸内幕" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/bee7d9c3fcf9" target="_blank" rel="noopener noreferrer">﻿日本核电站爆炸内幕</a></div><div class="_2GZFLj">正文 年R本政府宣布，位于F岛的核电站，受9级特大地震影响，放射性物质发生泄漏。R本人自食恶果不足惜，却给世界环境...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/0f438ff0a55f" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg" alt=""><span class="cwEQzo">茶点故事</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->38,767</span><span class="_3Q5ric">评论<!-- --> <!-- -->3</span><span class="_3Q5ric">赞<!-- --> <!-- -->303</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="男人毒药：我在死后第九天来索命" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/c2cfc4cb0aa7" target="_blank" rel="noopener noreferrer">男人毒药：我在死后第九天来索命</a></div><div class="_2GZFLj">文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹，春花似锦、人声如沸。这庄子的主人今日做“春日...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->29,850</span><span class="_3Q5ric">评论<!-- --> <!-- -->0</span><span class="_3Q5ric">赞<!-- --> <!-- -->19</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="一桩弑父案，背后竟有这般阴谋" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/c329b54bd638" target="_blank" rel="noopener noreferrer">一桩弑父案，背后竟有这般阴谋</a></div><div class="_2GZFLj">文/苍兰香墨 我抬头看了看天上的太阳。三九已至，却和暖如春，着一层夹袄步出监牢的瞬间，已是汗流浃背。 一阵脚步声响...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/5891e866c93e" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg" alt=""><span class="cwEQzo">开封第一讲书人</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->31,076</span><span class="_3Q5ric">评论<!-- --> <!-- -->1</span><span class="_3Q5ric">赞<!-- --> <!-- -->258</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="情欲美人皮" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/d79d2f48417f" target="_blank" rel="noopener noreferrer">情欲美人皮</a></div><div class="_2GZFLj">我被黑心中介骗来泰国打工， 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留，地道东北人。 一个月前我还...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/dcd395522934" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/783c64db-45e5-48d7-82e4-95736f50533e.jpg" alt=""><span class="cwEQzo">沈念sama</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->42,627</span><span class="_3Q5ric">评论<!-- --> <!-- -->2</span><span class="_3Q5ric">赞<!-- --> <!-- -->348</span></div></div></li><li class="_2DcRGJ"><div class="_34oaG3"><div class="_1ATS20" title="代替公主和亲" role="heading" aria-level="4"><a class="_37jvJB _1OhGeD" href="https://www.jianshu.com/p/fc890ed5083c" target="_blank" rel="noopener noreferrer">代替公主和亲</a></div><div class="_2GZFLj">正文 我出身青楼，却偏偏与公主长得像，于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子，可洞房花烛夜当晚...</div><div class="_19mMB9"><a class="_2t1QiF _1OhGeD" href="https://www.jianshu.com/u/0f438ff0a55f" target="_blank" rel="noopener noreferrer"><img class="_2bse80" src="./聊聊Linux 五种IO模型 - 简书_files/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg" alt=""><span class="cwEQzo">茶点故事</span></a><span class="_3Q5ric">阅读<!-- --> <!-- -->42,196</span><span class="_3Q5ric">评论<!-- --> <!-- -->2</span><span class="_3Q5ric">赞<!-- --> <!-- -->341</span></div></div></li></ul></section><div class="adad_container"></div><div id="note-page-comment"><div class="lazyload-placeholder"></div></div><section class="ouvJEz"><h3 class="QxT4hD"><span>被以下专题收入，发现更多相似内容</span></h3><div class="_2Nttfz"><div class="_3s5t0Q _1lsejJ" role="button" tabindex="-1" aria-label="收入我的专题"><i aria-label="ic-plus" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-plus"></use></svg></i><span class="_2-Djqu">收入我的专题</span></div><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/1e39c1b2d204" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/20210712200518.jpg" alt=""><span class="_2-Djqu">JAVA</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/8031139e1459" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/IMG_8115.JPG" alt=""><span class="_2-Djqu">Android...</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/023e94dd2689" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/二次元.jpeg" alt=""><span class="_2-Djqu">LinuxOS</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/0307931bb568" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/喝奶茶动漫短发美女_美腿_喝奶茶_车厢_4k动漫壁纸_彼岸图网.jpeg" alt=""><span class="_2-Djqu">Linux</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/d293a8abd10e" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/f725709af41bf0d5c05c3b127378113b.jpg" alt=""><span class="_2-Djqu">操作系统相关</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/787cb6867d39" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/4.jpg" alt=""><span class="_2-Djqu">Linux</span></a><a class="_3s5t0Q _1OhGeD" href="https://www.jianshu.com/c/5b0b8c491455" target="_blank" rel="noopener noreferrer"><img class="_2vEwGY" src="./聊聊Linux 五种IO模型 - 简书_files/1.jpg" alt=""><span class="_2-Djqu">计算机网络</span></a><div class="H7E3vT" role="button" tabindex="-1" aria-label="展开更多"><span>展开更多</span><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></div></div><div class="_19DgIp" style="margin-top:32px;margin-bottom:32px"></div><h3 class="QxT4hD"><span>推荐阅读</span><a class="_29KFEa _1OhGeD" href="https://www.jianshu.com/" target="_blank" rel="noopener noreferrer">更多精彩内容<i aria-label="ic-right" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-right"></use></svg></i></a></h3><ul class="_1iTR78"><li class="_11jppn"><div class="JB6qEE"><div class="em6wEs" title="linux 异步非异步阻塞非阻塞(转载 )" role="heading" aria-level="4"><a class="_2voXH8 _1OhGeD" href="https://www.jianshu.com/p/0aca498f50ca" target="_blank" rel="noopener noreferrer">linux 异步非异步阻塞非阻塞(转载 )</a></div><div class="_3fvgn4">转自: http://www.jianshu.com/p/486b0965c296  http://www.jia...</div><div class="_1pJt6F"><a class="_3IWz1q _1OhGeD" href="https://www.jianshu.com/u/b1bbc61e556a" target="_blank" rel="noopener noreferrer"><img class="_34VC_H" src="./聊聊Linux 五种IO模型 - 简书_files/5-33d2da32c552b8be9a0548c7a4576607.jpg" alt=""><span class="_3tPsL6">demop</span></a><span class="_31hjBO">阅读<!-- --> <!-- -->3,864</span><span class="_31hjBO">评论<!-- --> <!-- -->1</span><span class="_31hjBO">赞<!-- --> <!-- -->21</span></div></div></li><li class="_11jppn"><div class="JB6qEE"><div class="em6wEs" title="IO模型浅析" role="heading" aria-level="4"><a class="_2voXH8 _1OhGeD" href="https://www.jianshu.com/p/79e17d15dac2" target="_blank" rel="noopener noreferrer">IO模型浅析</a></div><div class="_3fvgn4">注：1）本人非科班出身，文章的来源主要是基于一些能找到的资料，在理解的基础上做一些总结归纳，以期对IO相关的知识体...</div><div class="_1pJt6F"><a class="_3IWz1q _1OhGeD" href="https://www.jianshu.com/u/39e23a5f710b" target="_blank" rel="noopener noreferrer"><img class="_34VC_H" src="./聊聊Linux 五种IO模型 - 简书_files/3-9a2bcc21a5d89e21dafc73b39dc5f582.jpg" alt=""><span class="_3tPsL6">Drew_Zhong</span></a><span class="_31hjBO">阅读<!-- --> <!-- -->997</span><span class="_31hjBO">评论<!-- --> <!-- -->0</span><span class="_31hjBO">赞<!-- --> <!-- -->2</span></div></div></li><li class="_11jppn"><div class="JB6qEE"><div class="em6wEs" title="第四模块： (1)并发编程" role="heading" aria-level="4"><a class="_2voXH8 _1OhGeD" href="https://www.jianshu.com/p/8cf1a2ccd3a8" target="_blank" rel="noopener noreferrer">第四模块： (1)并发编程</a></div><div class="_3fvgn4">必备的理论基础 1.操作系统作用： 隐藏丑陋复杂的硬件接口，提供良好的抽象接口。 管理调度进程，并将多个进程对硬件...</div><div class="_1pJt6F"><a class="_3IWz1q _1OhGeD" href="https://www.jianshu.com/u/f3af40cc9ff6" target="_blank" rel="noopener noreferrer"><img class="_34VC_H" src="./聊聊Linux 五种IO模型 - 简书_files/7-0993d41a595d6ab6ef17b19496eb2f21.jpg" alt=""><span class="_3tPsL6">drfung</span></a><span class="_31hjBO">阅读<!-- --> <!-- -->3,517</span><span class="_31hjBO">评论<!-- --> <!-- -->0</span><span class="_31hjBO">赞<!-- --> <!-- -->5</span></div></div></li><li class="_11jppn"><div class="JB6qEE"><div class="em6wEs" title="1. Unix五种IO模型与Java IO模型演进" role="heading" aria-level="4"><a class="_2voXH8 _1OhGeD" href="https://www.jianshu.com/p/ad0574a44c02" target="_blank" rel="noopener noreferrer">1. Unix五种IO模型与Java IO模型演进</a></div><div class="_3fvgn4">转自 http://www.tianshouzhi.com/api/tutorials/netty/221 同步异...</div><div class="_1pJt6F"><a class="_3IWz1q _1OhGeD" href="https://www.jianshu.com/u/03bdeaff31b9" target="_blank" rel="noopener noreferrer"><img class="_34VC_H" src="./聊聊Linux 五种IO模型 - 简书_files/13-394c31a9cb492fcb39c27422ca7d2815.jpg" alt=""><span class="_3tPsL6">沉沦2014</span></a><span class="_31hjBO">阅读<!-- --> <!-- -->1,277</span><span class="_31hjBO">评论<!-- --> <!-- -->0</span><span class="_31hjBO">赞<!-- --> <!-- -->7</span></div></div></li><li class="_11jppn"><div class="JB6qEE"><div class="em6wEs" title="Linux IO模式" role="heading" aria-level="4"><a class="_2voXH8 _1OhGeD" href="https://www.jianshu.com/p/9915f1213661" target="_blank" rel="noopener noreferrer">Linux IO模式</a></div><div class="_3fvgn4">参考 1. Linux IO模式及 select、poll、epoll详解 文章内容主要摘抄自1. Linux I...</div><div class="_1pJt6F"><a class="_3IWz1q _1OhGeD" href="https://www.jianshu.com/u/bb8b9b22cfd0" target="_blank" rel="noopener noreferrer"><img class="_34VC_H" src="./聊聊Linux 五种IO模型 - 简书_files/f39ea5e5-1b0b-4dbf-9ff4-fa5468046805.jpg" alt=""><span class="_3tPsL6">GOGOYAO</span></a><span class="_31hjBO">阅读<!-- --> <!-- -->603</span><span class="_31hjBO">评论<!-- --> <!-- -->0</span><span class="_31hjBO">赞<!-- --> <!-- -->1</span></div></div></li></ul></section></div><aside class="_2OwGUo"><section class="_3Z3nHf"><div class="_3Oo-T1"><a class="_1b5rv9 _1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" target="_blank" rel="noopener noreferrer"><img class="_3T9iJQ" src="./聊聊Linux 五种IO模型 - 简书_files/404b7397-cbe2-40cf-8f36-6c8d019c9788(3).jpeg" alt=""></a><div class="_32ZTTG"><div class="_2O0T_w"><div class="_2v-h3G"><span class="_2vh4fr" title="七寸知架构"><a class="_1OhGeD" href="https://www.jianshu.com/u/657c611b2e07" target="_blank" rel="noopener noreferrer">七寸知架构</a></span></div><button data-locale="zh-CN" type="button" class="tzrf9N _1OyPqC _3Mi9q9 _34692- ZccRSO"><span>已关注</span></button></div><div class="_1pXc22">总资产195</div></div></div><div class="_19DgIp"></div><div class="_26Hhi2" role="listitem"><div class="_3TNGId" title="☆啃碎并发（11）：内存模型之重排序"><a class="_2ER8Tt _1OhGeD" href="https://www.jianshu.com/p/b35dfe091dc4" target="_blank" rel="noopener noreferrer">☆啃碎并发（11）：内存模型之重排序</a></div><div class="DfvGP9">阅读 1,514</div></div><div class="_26Hhi2" role="listitem"><div class="_3TNGId" title="☆聊聊Dubbo（九）：核心源码-服务端启动流程1"><a class="_2ER8Tt _1OhGeD" href="https://www.jianshu.com/p/0015e7e420f1" target="_blank" rel="noopener noreferrer">☆聊聊Dubbo（九）：核心源码-服务端启动流程1</a></div><div class="DfvGP9">阅读 2,600</div></div></section><div><div aria-hidden="true" style="width: 260px; height: 530px;"></div><div class="ant-affix" style="position: fixed; top: 66px; width: 260px; height: 530px;"><section class="_3Z3nHf"><h3 class="_1Prj5h QxT4hD">热门故事</h3><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="桂林志异：龙王起水"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/9f168be225b0" target="_blank" rel="noopener noreferrer">桂林志异：龙王起水</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="离婚后，妈宝男前夫后悔了"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/ea8d12548641" target="_blank" rel="noopener noreferrer">离婚后，妈宝男前夫后悔了</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="救了他两次的神仙让他今天三更去死"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/1ded57e57939" target="_blank" rel="noopener noreferrer">救了他两次的神仙让他今天三更去死</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="我把眼角膜捐给丈夫的白月光后，他疯了 "><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/946923c8224f" target="_blank" rel="noopener noreferrer">我把眼角膜捐给丈夫的白月光后，他疯了 </a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="为了活命，我对病娇反派弟弟表白，他竟当真要做我夫君"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/abb1ac30da8b" target="_blank" rel="noopener noreferrer">为了活命，我对病娇反派弟弟表白，他竟当真要做我夫君</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="“有个坐过牢的富豪老公是种什么体验？”“要不然你来试试？”"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/0f38a77e0bd7" target="_blank" rel="noopener noreferrer">“有个坐过牢的富豪老公是种什么体验？”“要不然你来试试？”</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="前世渣男把我迷晕还叫我别怕，重生后我杀疯了"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/e8cfb8f2154e" target="_blank" rel="noopener noreferrer">前世渣男把我迷晕还叫我别怕，重生后我杀疯了</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="妹妹过失杀人，警察来时，我捡起了那把滴血的刀"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/3a1958255a4a" target="_blank" rel="noopener noreferrer">妹妹过失杀人，警察来时，我捡起了那把滴血的刀</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="我被校霸堵在巷口，却发现他是我谈了三个月的网恋对象"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/875b89eba857" target="_blank" rel="noopener noreferrer">我被校霸堵在巷口，却发现他是我谈了三个月的网恋对象</a></div></div><div class="_1jW5zV" role="listitem"><div class="_3QmNxJ" title="我首富之女的身份居然被人偷了"><a class="_3SxgBd _1OhGeD" href="https://www.jianshu.com/p/dbe39342ae8e" target="_blank" rel="noopener noreferrer">我首富之女的身份居然被人偷了</a></div></div></section></div></div></aside><div class="ant-back-top"><div class="_3MyrRP" role="button" tabindex="-1" aria-label="回到顶部"><i aria-label="icon: caret-up" class="anticon anticon-caret-up"><svg viewBox="0 0 1024 1024" focusable="false" class="" data-icon="caret-up" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M858.9 689L530.5 308.2c-9.4-10.9-27.5-10.9-37 0L165.1 689c-12.2 14.2-1.2 35 18.5 35h656.8c19.7 0 30.7-20.8 18.5-35z"></path></svg></i></div></div></div></div><footer style="width:100%"><div class="_2xr8G8"><div class="_1Jdfvb"><div class="TDvCqd"><textarea class="W2TSX_" placeholder="写下你的评论..."></textarea></div><div class="-pXE92"><div class="_3nj4GN" role="button" tabindex="0" aria-label="添加评论"><i aria-label="ic-reply" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-reply"></use></svg></i><span>评论<!-- -->57</span></div><div class="_3nj4GN _3oieia" role="button" tabindex="0" aria-label="给文章点赞"><i aria-label="ic-like" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-like"></use></svg></i><span>赞<!-- -->445</span></div><div class="_3nj4GN ant-dropdown-trigger" role="button" tabindex="0" aria-label="更多操作"><i aria-label="ic-others" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-others"></use></svg></i></div></div></div></div><div class="_1LI0En" style="height: 56px;"></div></footer><div class="_3Pnjry"><div class="_1pUUKr _2Z1aZJ"><div class="_2VdqdF" role="button" tabindex="-1" aria-label="给文章点赞"><i aria-label="ic-like" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-like"></use></svg></i></div><div class="P63n6G"><div class="_2LKTFF"><span class="_1GPnWJ RhY_sp">446<!-- -->赞</span><span class="_1GPnWJ" role="button" tabindex="-1" aria-label="查看点赞列表">445<!-- -->赞</span></div></div></div><div class="_1pUUKr"><div class="_2VdqdF" role="button" tabindex="-1" aria-label="赞赏作者"><i aria-label="ic-shang" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-shang"></use></svg></i></div><div class="P63n6G" role="button" tabindex="-1" aria-label="查看赞赏列表">5<!-- -->赞赏</div></div><div class="_1pUUKr"><img class="_2VdqdF" src=""><div class="P63n6G">手机看全文</div></div></div></div><script async="" src="聊聊Linux%20五种IO模型%20-%20简书_files/hm.js.下载"></script><script async="" src="聊聊Linux%20五种IO模型%20-%20简书_files/analytics.js.下载"></script><script id="__NEXT_DATA__" type="application/json">{"dataManager":"[]","props":{"isServer":true,"initialState":{"global":{"done":false,"artFromType":null,"fontType":"black","$modal":{"ContributeModal":false,"RewardListModal":false,"PayModal":false,"CollectionModal":false,"DownloadAppQRModal":false,"LikeListModal":false,"ReportModal":false,"QRCodeShareModal":false,"BookCatalogModal":false,"RewardModal":false},"$ua":{"value":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36","isIE11":false,"earlyIE":null,"chrome":"130.0","firefox":null,"safari":null,"isMac":false},"$diamondRate":{"displayable":false,"rate":0},"underRecomment":[{"note":{"title":"人面猴","slug":"1003a129be45","likes_count":473,"views_count":201468,"public_abbr":"序言：七十年代末，一起剥皮案震惊了整个滨河市，随后出现的几起案子，更是在滨河造成了极大的恐慌，老刑警刘岩，带你破解...","comments_size":5},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"死咒","slug":"1c4506f51019","likes_count":377,"views_count":84620,"public_abbr":"序言：滨河连续发生了三起死亡事件，死亡现场离奇诡异，居然都是意外死亡，警方通过查阅死者的电脑和手机，发现死者居然都...","comments_size":2},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"救了他两次的神仙让他今天三更去死","slug":"1ded57e57939","likes_count":334,"views_count":148427,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-7023945eba5c7188.jpg","public_abbr":"文/潘晓璐 我一进店门，熙熙楼的掌柜王于贵愁眉苦脸地迎上来，“玉大人，你说我怎么就摊上这事。” “怎么了？”我有些...","comments_size":0},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"道士缉凶录：失踪的卖姜人","slug":"25685c1b1f2b","likes_count":272,"views_count":54160,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-78ddb930c2ecef7f.jpg","public_abbr":"   文/不坏的土叔    我叫张陵，是天一观的道长。 经常有香客问我，道长，这世上最难降的妖魔是什么？ 我笑而不...","comments_size":1},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"﻿港岛之恋（遗憾婚礼）","slug":"553802eff5d6","likes_count":363,"views_count":63197,"public_abbr":"正文 为了忘掉前任，我火速办了婚礼，结果婚礼上，老公的妹妹穿的比我还像新娘。我一直安慰自己，他们只是感情好，可当我...","comments_size":5},"user":{"slug":"0f438ff0a55f","nickname":"茶点故事","avatar":"https://upload.jianshu.io/users/upload_avatars/4790772/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg"}},{"note":{"title":"恶毒庶女顶嫁案：这布局不是一般人想出来的","slug":"59985a89b4ef","likes_count":281,"views_count":48334,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-e4863d2f2866d202.jpg","public_abbr":"文/花漫 我一把揭开白布。 她就那样静静地躺着，像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上，一...","comments_size":1},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"城市分裂传说","slug":"62a01de427e0","likes_count":393,"views_count":37775,"public_abbr":"那天，我揣着相机与录音，去河边找鬼。 笑死，一个胖子当着我的面吹牛，可吹牛的内容都是我干的。 我是一名探鬼主播，决...","comments_size":3},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"双鸳鸯连环套：你想象不到人心有多黑","slug":"6ccdc163474a","likes_count":256,"views_count":36444,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-fcf609995c0512c6.jpg","public_abbr":"文/苍兰香墨 我猛地睁开眼，长吁一口气：“原来是场噩梦啊……” “哼！你这毒妇竟也来了？” 一声冷哼从身侧响起，我...","comments_size":0},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"万荣杀人案实录","slug":"8796e3463067","likes_count":295,"views_count":40628,"public_abbr":"序言：老挝万荣一对情侣失踪，失踪者是张志新（化名）和其女友刘颖，没想到半个月后，有当地人在树林里发现了一具尸体，经...","comments_size":1},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"﻿护林员之死","slug":"8a691dd8fa34","likes_count":317,"views_count":35459,"public_abbr":"正文 独居荒郊野岭守林人离奇死亡，尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...","comments_size":2},"user":{"slug":"0f438ff0a55f","nickname":"茶点故事","avatar":"https://upload.jianshu.io/users/upload_avatars/4790772/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg"}},{"note":{"title":"﻿白月光启示录","slug":"a5293fa3b5e0","likes_count":329,"views_count":37508,"public_abbr":"正文 我和宋清朗相恋三年，在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...","comments_size":1},"user":{"slug":"0f438ff0a55f","nickname":"茶点故事","avatar":"https://upload.jianshu.io/users/upload_avatars/4790772/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg"}},{"note":{"title":"活死人","slug":"a83aa7e71001","likes_count":318,"views_count":33210,"public_abbr":"序言：一个原本活蹦乱跳的男人离奇死亡，死状恐怖，灵堂内的尸体忽然破棺而出，到底是诈尸还是另有隐情，我是刑警宁泽，带...","comments_size":3},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"﻿日本核电站爆炸内幕","slug":"bee7d9c3fcf9","likes_count":303,"views_count":38767,"public_abbr":"正文 年R本政府宣布，位于F岛的核电站，受9级特大地震影响，放射性物质发生泄漏。R本人自食恶果不足惜，却给世界环境...","comments_size":3},"user":{"slug":"0f438ff0a55f","nickname":"茶点故事","avatar":"https://upload.jianshu.io/users/upload_avatars/4790772/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg"}},{"note":{"title":"男人毒药：我在死后第九天来索命","slug":"c2cfc4cb0aa7","likes_count":19,"views_count":29850,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-d9603b43418718ad.jpg","public_abbr":"文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹，春花似锦、人声如沸。这庄子的主人今日做“春日...","comments_size":0},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"一桩弑父案，背后竟有这般阴谋","slug":"c329b54bd638","likes_count":258,"views_count":31076,"list_image_url":"https://upload-images.jianshu.io/upload_images/28970511-b32b7ade71ae4924.jpg","public_abbr":"文/苍兰香墨 我抬头看了看天上的太阳。三九已至，却和暖如春，着一层夹袄步出监牢的瞬间，已是汗流浃背。 一阵脚步声响...","comments_size":1},"user":{"slug":"5891e866c93e","nickname":"开封第一讲书人","avatar":"https://cdn2.jianshu.io/assets/default_avatar/8-a356878e44b45ab268a3b0bbaaadeeb7.jpg"}},{"note":{"title":"情欲美人皮","slug":"d79d2f48417f","likes_count":348,"views_count":42627,"public_abbr":"我被黑心中介骗来泰国打工， 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留，地道东北人。 一个月前我还...","comments_size":2},"user":{"slug":"dcd395522934","nickname":"沈念sama","avatar":"https://upload.jianshu.io/users/upload_avatars/15878160/783c64db-45e5-48d7-82e4-95736f50533e.jpg"}},{"note":{"title":"代替公主和亲","slug":"fc890ed5083c","likes_count":341,"views_count":42196,"public_abbr":"正文 我出身青楼，却偏偏与公主长得像，于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子，可洞房花烛夜当晚...","comments_size":2},"user":{"slug":"0f438ff0a55f","nickname":"茶点故事","avatar":"https://upload.jianshu.io/users/upload_avatars/4790772/388e473c-fe2f-40e0-9301-e357ae8f1b41.jpeg"}}],"readMode":"night","locale":"zh-CN","seoList":[{"comments_count":1,"public_abbr":"转自: http://www.jianshu.com/p/486b0965c296  http://www.jia...","share_image_url":"http://upload-images.jianshu.io/upload_images/2148014-474fbcf2ef05accd.png","slug":"0aca498f50ca","user":{"id":2148014,"nickname":"demop","slug":"b1bbc61e556a","avatar":"https://cdn2.jianshu.io/assets/default_avatar/5-33d2da32c552b8be9a0548c7a4576607.jpg"},"likes_count":21,"title":"linux 异步非异步阻塞非阻塞(转载 )","id":10156994,"views_count":3864},{"comments_count":0,"public_abbr":"注：1）本人非科班出身，文章的来源主要是基于一些能找到的资料，在理解的基础上做一些总结归纳，以期对IO相关的知识体...","share_image_url":"","slug":"79e17d15dac2","user":{"id":7091173,"nickname":"Drew_Zhong","slug":"39e23a5f710b","avatar":"https://cdn2.jianshu.io/assets/default_avatar/3-9a2bcc21a5d89e21dafc73b39dc5f582.jpg"},"likes_count":2,"title":"IO模型浅析","id":28774452,"views_count":997},{"comments_count":0,"public_abbr":"必备的理论基础 1.操作系统作用： 隐藏丑陋复杂的硬件接口，提供良好的抽象接口。 管理调度进程，并将多个进程对硬件...","share_image_url":"http://upload-images.jianshu.io/upload_images/6078939-d31eb8c1901bbf15.png","slug":"8cf1a2ccd3a8","user":{"id":6078939,"nickname":"drfung","slug":"f3af40cc9ff6","avatar":"https://cdn2.jianshu.io/assets/default_avatar/7-0993d41a595d6ab6ef17b19496eb2f21.jpg"},"likes_count":5,"title":"第四模块： (1)并发编程","id":28267855,"views_count":3517},{"comments_count":0,"public_abbr":"转自 http://www.tianshouzhi.com/api/tutorials/netty/221 同步异...","share_image_url":"http://upload-images.jianshu.io/upload_images/7378149-55b58414fcfc6501.png","slug":"ad0574a44c02","user":{"id":7378149,"nickname":"沉沦2014","slug":"03bdeaff31b9","avatar":"https://cdn2.jianshu.io/assets/default_avatar/13-394c31a9cb492fcb39c27422ca7d2815.jpg"},"likes_count":7,"title":"1. Unix五种IO模型与Java IO模型演进","id":32667504,"views_count":1277},{"comments_count":0,"public_abbr":"参考 1. Linux IO模式及 select、poll、epoll详解 文章内容主要摘抄自1. Linux I...","share_image_url":"https://upload-images.jianshu.io/upload_images/5021195-c497fe3a670c59da.png","slug":"9915f1213661","user":{"id":5021195,"nickname":"GOGOYAO","slug":"bb8b9b22cfd0","avatar":"https://upload.jianshu.io/users/upload_avatars/5021195/f39ea5e5-1b0b-4dbf-9ff4-fa5468046805.jpg"},"likes_count":1,"title":"Linux IO模式","id":50471184,"views_count":603}]},"note":{"data":{"is_author":false,"last_updated_at":1620571436,"public_title":"聊聊Linux 五种IO模型","purchased":false,"liked_note":true,"comments_count":57,"free_content":"\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 354px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 18.34%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1930\" data-height=\"354\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png\" data-original-width=\"1930\" data-original-height=\"354\" data-original-format=\"image/png\" data-original-filesize=\"281105\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e个人主页，扫码关注\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e上一篇\u003ca href=\"https://www.jianshu.com/p/aed6067eeac9\" target=\"_blank\"\u003e《聊聊同步、异步、阻塞与非阻塞》\u003c/a\u003e已经通俗的讲解了，要理解同步、异步、阻塞与非阻塞重要的两个概念点了，没有看过的，建议先看这篇博文理解这两个概念点。在认知上，建立统一的模型。这样，大家在继续看本篇时，才不会理解有偏差。\u003c/p\u003e\n\u003cp\u003e那么，在正式开始讲Linux IO模型前，比如：同步IO和异步IO，阻塞IO和非阻塞IO分别是什么，到底有什么区别？不同的人在不同的上下文下给出的答案是不同的。所以先限定一下本文的上下文。\u003c/p\u003e\n\u003ch1\u003e1 概念说明\u003c/h1\u003e\n\u003cp\u003e在进行解释之前，首先要说明几个概念：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e用户空间和内核空间\u003c/p\u003e\n\u003cp\u003e进程切换\u003c/p\u003e\n\u003cp\u003e进程的阻塞\u003c/p\u003e\n\u003cp\u003e文件描述符\u003c/p\u003e\n\u003cp\u003e缓存 IO\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2\u003e1.1 用户空间与内核空间\u003c/h2\u003e\n\u003cp\u003e现在操作系统都是采用虚拟存储器，那么对32位操作系统而言，它的寻址空间（虚拟存储空间）为4G（2的32次方）。\u003ccode\u003e操作系统的核心是内核，独立于普通的应用程序，可以访问受保护的内存空间，也有访问底层硬件设备的所有权限\u003c/code\u003e。为了保证用户进程不能直接操作内核（kernel），保证内核的安全，\u003ccode\u003e操作系统将虚拟空间划分为两部分，一部分为内核空间，一部分为用户空间\u003c/code\u003e。针对linux操作系统而言，将最高的1G字节（从虚拟地址0xC0000000到0xFFFFFFFF），供内核使用，称为内核空间，而将较低的3G字节（从虚拟地址0x00000000到0xBFFFFFFF），供各个进程使用，称为用户空间。\u003c/p\u003e\n\u003ch2\u003e1.2 进程切换\u003c/h2\u003e\n\u003cp\u003e为了控制进程的执行，内核必须有能力挂起正在CPU上运行的进程，并恢复以前挂起的某个进程的执行。这种行为被称为进程切换。因此可以说，任何进程都是在操作系统内核的支持下运行的，是与内核紧密相关的。\u003c/p\u003e\n\u003cp\u003e从一个进程的运行转到另一个进程上运行，这个过程中经过下面这些变化：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003e保存处理机上下文，包括程序计数器和其他寄存器。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e更新PCB信息。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e把进程的PCB移入相应的队列，如就绪、在某事件阻塞等队列。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e选择另一个进程执行，并更新其PCB。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e更新内存管理的数据结构。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e恢复处理机上下文。\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e注：总而言之就是很耗资源，具体的可以参考这篇文章：\u003ca href=\"https://links.jianshu.com/go?to=http%3A%2F%2Fguojing.me%2Flinux-kernel-architecture%2Fposts%2Fprocess-switch%2F\" target=\"_blank\"\u003e进程切换\u003c/a\u003e。\u003c/p\u003e\n\u003ch2\u003e1.3 进程的阻塞\u003c/h2\u003e\n\u003cp\u003e正在执行的进程，由于期待的某些事件未发生，如请求系统资源失败、等待某种操作的完成、新数据尚未到达或无新工作做等，则由系统自动执行阻塞原语(Block)，使自己由运行状态变为阻塞状态。可见，进程的阻塞是进程自身的一种主动行为，也因此只有处于运行态的进程（获得CPU），才可能将其转为阻塞状态。\u003ccode\u003e当进程进入阻塞状态，是不占用CPU资源的\u003c/code\u003e。\u003c/p\u003e\n\u003ch2\u003e1.4 文件描述符fd\u003c/h2\u003e\n\u003cp\u003e文件描述符（File descriptor）是计算机科学中的一个术语，\u003ccode\u003e是一个用于表述指向文件的引用的抽象化概念\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e文件描述符在形式上是一个非负整数。实际上，\u003ccode\u003e它是一个索引值，指向内核为每一个进程所维护的该进程打开文件的记录表\u003c/code\u003e。当程序打开一个现有文件或者创建一个新文件时，内核向进程返回一个文件描述符。在程序设计中，一些涉及底层的程序编写往往会围绕着文件描述符展开。但是文件描述符这一概念往往只适用于UNIX、Linux这样的操作系统。\u003c/p\u003e\n\u003ch2\u003e1.5 缓存 IO\u003c/h2\u003e\n\u003cp\u003e\u003ccode\u003e缓存 IO 又被称作标准 IO，大多数文件系统的默认 IO 操作都是缓存 IO\u003c/code\u003e。在 Linux 的缓存 IO 机制中，操作系统会将 IO 的数据缓存在文件系统的页缓存（ page cache ）中，也就是说，\u003ccode\u003e数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e缓存 IO 的缺点：\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e数据在传输过程中需要在应用程序地址空间和内核进行多次数据拷贝操作\u003c/code\u003e，这些数据拷贝操作所带来的 CPU 以及内存开销是非常大的。\u003c/p\u003e\n\u003ch1\u003e2 Linux IO模型\u003c/h1\u003e\n\u003cp\u003e\u003ccode\u003e网络IO的本质是socket的读取，socket在linux系统被抽象为流，IO可以理解为对流的操作\u003c/code\u003e。刚才说了，对于一次IO访问（以read举例），\u003ccode\u003e数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间\u003c/code\u003e。所以说，当一个read操作发生时，它会经历两个阶段：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003e第一阶段：等待数据准备 (Waiting for the data to be ready)。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e第二阶段：将数据从内核拷贝到进程中 (Copying the data from the kernel to the process)。\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e对于socket流而言，\u003c/p\u003e\n\u003cblockquote\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003e第一步：通常涉及等待网络上的数据分组到达，然后被复制到内核的某个缓冲区。\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e第二步：把数据从内核缓冲区复制到应用进程缓冲区。\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e网络应用需要处理的无非就是两大类问题，\u003ccode\u003e网络IO，数据计算\u003c/code\u003e。相对于后者，网络IO的延迟，给应用带来的性能瓶颈大于后者。网络IO的模型大致有如下几种：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003e同步模型（synchronous IO）\u003c/strong\u003e\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e阻塞IO（bloking IO）\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e非阻塞IO（non-blocking IO）\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e多路复用IO（multiplexing IO）\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e信号驱动式IO（signal-driven IO）\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003e异步IO（asynchronous IO）\u003c/strong\u003e\u003c/p\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cstrong\u003e\u003ccode\u003e注：由于signal driven IO在实际中并不常用，所以我这只提及剩下的四种IO Model。\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e在深入介绍Linux IO各种模型之前，让我们先来探索一下基本 Linux IO 模型的简单矩阵。如下图所示：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 460px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 58.52%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"786\" data-height=\"460\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-49ac9eb7d4d2d019.png\" data-original-width=\"786\" data-original-height=\"460\" data-original-format=\"image/png\" data-original-filesize=\"46987\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e每个 IO 模型都有自己的使用模式，它们对于特定的应用程序都有自己的优点。本节将简要对其一一进行介绍。\u003ccode\u003e常见的IO模型有阻塞、非阻塞、IO多路复用，异步\u003c/code\u003e。以一个生动形象的例子来说明这四个概念。周末我和女友去逛街，中午饿了，我们准备去吃饭。周末人多，吃饭需要排队，我和女友有以下几种方案。\u003c/p\u003e\n\u003ch2\u003e2.1 同步阻塞 IO（blocking IO）\u003c/h2\u003e\n\u003ch3\u003e2.1.1 场景描述\u003c/h3\u003e\n\u003cblockquote\u003e\n\u003cp\u003e我和女友点完餐后，不知道什么时候能做好，只好坐在餐厅里面等，直到做好，然后吃完才离开。女友本想还和我一起逛街的，但是不知道饭能什么时候做好，只好和我一起在餐厅等，而不能去逛街，直到吃完饭才能去逛街，中间等待做饭的时间浪费掉了。\u003ccode\u003e这就是典型的阻塞\u003c/code\u003e。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch3\u003e2.1.2 网络模型\u003c/h3\u003e\n\u003cp\u003e\u003ccode\u003e同步阻塞 IO 模型是最常用的一个模型，也是最简单的模型\u003c/code\u003e。在linux中，\u003ccode\u003e默认情况下所有的socket都是blocking\u003c/code\u003e。它符合人们最常见的思考逻辑。\u003ccode\u003e阻塞就是进程 \"被\" 休息, CPU处理其它进程去了\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e在这个IO模型中，用户空间的应用程序执行一个系统调用（recvform），这会导致应用程序阻塞，什么也不干，直到数据准备好，并且将数据从内核复制到用户进程，最后进程再处理数据，\u003ccode\u003e在等待数据到处理数据的两个阶段\u003c/code\u003e，整个进程都被阻塞。不能处理别的网络IO。\u003ccode\u003e调用应用程序处于一种不再消费 CPU 而只是简单等待响应的状态\u003c/code\u003e，因此从处理的角度来看，这是非常有效的。在调用recv()/recvfrom()函数时，发生在内核中等待数据和复制数据的过程，大致如下图：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 646px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 54.559999999999995%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1184\" data-height=\"646\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-41550941d72be698.png\" data-original-width=\"1184\" data-original-height=\"646\" data-original-format=\"image/png\" data-original-filesize=\"183722\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003ch3\u003e2.1.3 流程描述\u003c/h3\u003e\n\u003cp\u003e当用户进程调用了recv()/recvfrom()这个系统调用，\u003ccode\u003ekernel就开始了IO的第一个阶段：准备数据\u003c/code\u003e（对于网络IO来说，很多时候数据在一开始还没有到达。比如，还没有收到一个完整的UDP包。这个时候kernel就要等待足够的数据到来）。这个过程需要等待，也就是说数据被拷贝到操作系统内核的缓冲区中是需要一个过程的。而在用户进程这边，整个进程会被阻塞（当然，是进程自己选择的阻塞）。\u003ccode\u003e第二个阶段：当kernel一直等到数据准备好了，它就会将数据从kernel中拷贝到用户内存\u003c/code\u003e，然后kernel返回结果，用户进程才解除block的状态，重新运行起来。\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e所以，blocking IO的特点就是在IO执行的两个阶段都被block了。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cstrong\u003e优点：\u003c/strong\u003e\u003c/p\u003e\n\u003cblockquote\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003e能够及时返回数据，无延迟；\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e对内核开发者来说这是省事了；\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cstrong\u003e缺点：\u003c/strong\u003e\u003c/p\u003e\n\u003cblockquote\u003e\n\u003col\u003e\n\u003cli\u003e对用户来说处于等待就要付出性能的代价了；\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/blockquote\u003e\n\u003ch2\u003e2.2 同步非阻塞 IO（nonblocking IO）\u003c/h2\u003e\n\u003ch3\u003e2.2.1 场景描述\u003c/h3\u003e\n\u003cblockquote\u003e\n\u003cp\u003e我女友不甘心白白在这等，又想去逛商场，又担心饭好了。所以我们逛一会，回来询问服务员饭好了没有，来来回回好多次，饭都还没吃都快累死了啦。\u003ccode\u003e这就是非阻塞\u003c/code\u003e。需要不断的询问，是否准备好了。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch3\u003e2.2.2 网络模型\u003c/h3\u003e\n\u003cp\u003e\u003ccode\u003e同步非阻塞就是 “每隔一会儿瞄一眼进度条” 的轮询（polling）方式\u003c/code\u003e。在这种模型中，\u003ccode\u003e设备是以非阻塞的形式打开的\u003c/code\u003e。这意味着 IO 操作不会立即完成，read 操作可能会返回一个错误代码，说明这个命令不能立即满足（EAGAIN 或 EWOULDBLOCK）。\u003c/p\u003e\n\u003cp\u003e在网络IO时候，非阻塞IO也会进行recvform系统调用，检查数据是否准备好，与阻塞IO不一样，\"非阻塞将大的整片时间的阻塞分成N多的小的阻塞, 所以进程不断地有机会 '被' CPU光顾\"。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e也就是说非阻塞的recvform系统调用调用之后，进程并没有被阻塞，内核马上返回给进程，如果数据还没准备好，此时会返回一个error\u003c/code\u003e。进程在返回之后，可以干点别的事情，然后再发起recvform系统调用。重复上面的过程，循环往复的进行recvform系统调用。\u003ccode\u003e这个过程通常被称之为轮询\u003c/code\u003e。轮询检查内核数据，直到数据准备好，再拷贝数据到进程，进行数据处理。\u003cstrong\u003e\u003ccode\u003e需要注意，拷贝数据整个过程，进程仍然是属于阻塞的状态\u003c/code\u003e\u003c/strong\u003e。\u003c/p\u003e\n\u003cp\u003e在linux下，可以通过设置socket使其变为non-blocking。\u003ccode\u003e当对一个non-blocking socket执行读操作时\u003c/code\u003e，流程如图所示：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 638px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 54.620000000000005%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1168\" data-height=\"638\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-69746d536c2781da.png\" data-original-width=\"1168\" data-original-height=\"638\" data-original-format=\"image/png\" data-original-filesize=\"262569\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003ch3\u003e2.2.3 流程描述\u003c/h3\u003e\n\u003cp\u003e当用户进程发出read操作时，如果kernel中的数据还没有准备好，那么它并不会block用户进程，而是立刻返回一个error。从用户进程角度讲，它发起一个read操作后，并不需要等待，而是马上就得到了一个结果。用户进程判断结果是一个error时，它就知道数据还没有准备好，于是它可以再次发送read操作。一旦kernel中的数据准备好了，并且又再次收到了用户进程的system call，那么它马上就将数据拷贝到了用户内存，然后返回。\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e所以，nonblocking IO的特点是用户进程需要不断的主动询问kernel数据好了没有。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cstrong\u003e同步非阻塞方式相比同步阻塞方式：\u003c/strong\u003e\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e优点：能够在等待任务完成的时间里干其他活了（包括提交其他任务，也就是 “后台” 可以有多个任务在同时执行）。\u003c/p\u003e\n\u003cp\u003e缺点：任务完成的响应延迟增大了，因为每过一段时间才去轮询一次read操作，而任务可能在两次轮询之间的任意时间完成。这会导致整体数据吞吐量的降低。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2\u003e2.3 IO 多路复用（ IO multiplexing）\u003c/h2\u003e\n\u003ch3\u003e2.3.1 场景描述\u003c/h3\u003e\n\u003cblockquote\u003e\n\u003cp\u003e与第二个方案差不多，餐厅安装了电子屏幕用来显示点餐的状态，这样我和女友逛街一会，回来就不用去询问服务员了，直接看电子屏幕就可以了。这样每个人的餐是否好了，都直接看电子屏幕就可以了，\u003ccode\u003e这就是典型的IO多路复用\u003c/code\u003e。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch3\u003e2.3.2 网络模型\u003c/h3\u003e\n\u003cp\u003e由于同步非阻塞方式需要不断主动轮询，轮询占据了很大一部分过程，轮询会消耗大量的CPU时间，而 “后台” 可能有多个任务在同时进行，人们就想到了循环查询多个任务的完成状态，只要有任何一个任务完成，就去处理它。如果轮询不是进程的用户态，而是有人帮忙就好了。\u003ccode\u003e那么这就是所谓的 “IO 多路复用”\u003c/code\u003e。UNIX/Linux 下的 select、poll、epoll 就是干这个的（epoll 比 poll、select 效率高，做的事情是一样的）。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eIO多路复用有两个特别的系统调用select、poll、epoll函数\u003c/code\u003e。select调用是内核级别的，select轮询相对非阻塞的轮询的区别在于---\u003ccode\u003e前者可以等待多个socket，能实现同时对多个IO端口进行监听\u003c/code\u003e，当其中任何一个socket的数据准好了，\u003ccode\u003e就能返回进行可读\u003c/code\u003e，\u003ccode\u003e然后进程再进行recvform系统调用，将数据由内核拷贝到用户进程，当然这个过程是阻塞的\u003c/code\u003e。select或poll调用之后，会阻塞进程，与blocking IO阻塞不同在于，\u003ccode\u003e此时的select不是等到socket数据全部到达再处理, 而是有了一部分数据就会调用用户进程来处理\u003c/code\u003e。如何知道有一部分数据到达了呢？\u003ccode\u003e监视的事情交给了内核，内核负责数据到达的处理。也可以理解为\"非阻塞\"吧\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eI/O复用模型会用到select、poll、epoll函数，这几个函数也会使进程阻塞，但是和阻塞I/O所不同的的，这两个函数可以同时阻塞多个I/O操作\u003c/code\u003e。而且可以同时对多个读操作，多个写操作的I/O函数进行检测，直到有数据可读或可写时（注意不是全部数据可读或可写），才真正调用I/O操作函数。\u003c/p\u003e\n\u003cp\u003e对于多路复用，也就是轮询多个socket。\u003ccode\u003e多路复用既然可以处理多个IO，也就带来了新的问题，多个IO之间的顺序变得不确定了\u003c/code\u003e，当然也可以针对不同的编号。具体流程，如下图所示：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 588px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 52.129999999999995%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1128\" data-height=\"588\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-d552e1e2ca381a08.png\" data-original-width=\"1128\" data-original-height=\"588\" data-original-format=\"image/png\" data-original-filesize=\"246096\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003ch3\u003e2.3.3 流程描述\u003c/h3\u003e\n\u003cp\u003eIO multiplexing就是我们说的select，poll，epoll，有些地方也称这种IO方式为event driven IO。\u003ccode\u003eselect/epoll的好处就在于单个process就可以同时处理多个网络连接的IO\u003c/code\u003e。它的基本原理就是select，poll，epoll这个function会不断的轮询所负责的所有socket，当某个socket有数据到达了，就通知用户进程。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e当用户进程调用了select，那么整个进程会被block\u003c/code\u003e，而同时，kernel会“监视”所有select负责的socket，\u003ccode\u003e当任何一个socket中的数据准备好了，select就会返回\u003c/code\u003e。这个时候用户进程再调用read操作，将数据从kernel拷贝到用户进程。\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e多路复用的特点是\u003ccode\u003e通过一种机制一个进程能同时等待IO文件描述符\u003c/code\u003e，内核监视这些文件描述符（套接字描述符），其中的任意一个进入读就绪状态，select， poll，epoll函数就可以返回。对于监视的方式，又可以分为 select， poll， epoll三种方式。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e上面的图和blocking IO的图其实并没有太大的不同，事实上，还更差一些。\u003ccode\u003e因为这里需要使用两个system call (select 和 recvfrom)，而blocking IO只调用了一个system call (recvfrom)\u003c/code\u003e。但是，\u003ccode\u003e用select的优势在于它可以同时处理多个connection\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e所以，如果处理的连接数不是很高的话，使用select/epoll的web server不一定比使用multi-threading + blocking IO的web server性能更好，可能延迟还更大。（select/epoll的优势并不是对于单个连接能处理得更快，而是在于能处理更多的连接。）\u003c/p\u003e\n\u003cp\u003e在IO multiplexing Model中，\u003ccode\u003e实际中，对于每一个socket，一般都设置成为non-blocking\u003c/code\u003e，但是，如上图所示，整个用户的process其实是一直被block的。\u003ccode\u003e只不过process是被select这个函数block，而不是被socket IO给block\u003c/code\u003e。所以\u003cstrong\u003e\u003ccode\u003eIO多路复用是阻塞在select，epoll这样的系统调用之上，而没有阻塞在真正的I/O系统调用如recvfrom之上。\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e在I/O编程过程中，\u003ccode\u003e当需要同时处理多个客户端接入请求时，可以利用多线程或者I/O多路复用技术进行处理\u003c/code\u003e。I/O多路复用技术\u003ccode\u003e通过把多个I/O的阻塞复用到同一个select的阻塞上，从而使得系统在单线程的情况下可以同时处理多个客户端请求\u003c/code\u003e。与传统的多线程/多进程模型比，\u003ccode\u003eI/O多路复用的最大优势是系统开销小\u003c/code\u003e，系统不需要创建新的额外进程或者线程，也不需要维护这些进程和线程的运行，降底了系统的维护工作量，节省了系统资源，I/O多路复用的主要应用场景如下：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e服务器需要同时处理多个处于监听状态或者多个连接状态的套接字。\u003c/p\u003e\n\u003cp\u003e服务器需要同时处理多种网络协议的套接字。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e了解了前面三种IO模式，在用户进程进行系统调用的时候，\u003cstrong\u003e\u003ccode\u003e他们在等待数据到来的时候，处理的方式不一样，直接等待，轮询，select或poll轮询\u003c/code\u003e\u003c/strong\u003e，两个阶段过程：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e第一个阶段有的阻塞，有的不阻塞，有的可以阻塞又可以不阻塞。\u003c/p\u003e\n\u003cp\u003e第二个阶段都是阻塞的。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cstrong\u003e\u003ccode\u003e从整个IO过程来看，他们都是顺序执行的，因此可以归为同步模型(synchronous)。都是进程主动等待且向内核检查状态。【此句很重要！！！】\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e高并发的程序一般使用同步非阻塞方式而非多线程 + 同步阻塞方式\u003c/code\u003e。要理解这一点，首先要扯到并发和并行的区别。比如去某部门办事需要依次去几个窗口，\u003ccode\u003e办事大厅里的人数就是并发数，而窗口个数就是并行度\u003c/code\u003e。也就是说\u003ccode\u003e并发数是指同时进行的任务数（如同时服务的 HTTP 请求）\u003c/code\u003e，而\u003ccode\u003e并行数是可以同时工作的物理资源数量（如 CPU 核数）\u003c/code\u003e。通过合理调度任务的不同阶段，并发数可以远远大于并行度，这就是区区几个 CPU 可以支持上万个用户并发请求的奥秘。在这种高并发的情况下，为每个任务（用户请求）创建一个进程或线程的开销非常大。\u003ccode\u003e而同步非阻塞方式可以把多个 IO 请求丢到后台去，这就可以在一个进程里服务大量的并发 IO 请求\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e注意：IO多路复用是同步阻塞模型还是异步阻塞模型，在此给大家分析下：\u003c/strong\u003e\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e此处仍然不太清楚的，强烈建议大家在细究\u003ca href=\"https://links.jianshu.com/go?to=http%3A%2F%2Fmy.oschina.net%2Fxianggao%2Fblog%2F661085\" target=\"_blank\"\u003e《聊聊同步、异步、阻塞与非阻塞》\u003c/a\u003e中讲同步与异步的根本性区别，\u003ccode\u003e同步是需要主动等待消息通知，而异步则是被动接收消息通知，通过回调、通知、状态等方式来被动获取消息\u003c/code\u003e。\u003ccode\u003eIO多路复用在阻塞到select阶段时，用户进程是主动等待并调用select函数获取数据就绪状态消息，并且其进程状态为阻塞\u003c/code\u003e。所以，\u003ccode\u003e把IO多路复用归为同步阻塞模式\u003c/code\u003e。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2\u003e2.4 信号驱动式IO（signal-driven IO）\u003c/h2\u003e\n\u003cp\u003e信号驱动式I/O：首先我们允许Socket进行信号驱动IO,并安装一个信号处理函数，进程继续运行并不阻塞。当数据准备好时，进程会收到一个SIGIO信号，可以在信号处理函数中调用I/O操作函数处理数据。过程如下图所示：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 446px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 63.59%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1192\" data-height=\"758\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-222408c76186fd8c.png\" data-original-width=\"1192\" data-original-height=\"758\" data-original-format=\"image/png\" data-original-filesize=\"210403\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003ch2\u003e2.5 异步非阻塞 IO（asynchronous IO）\u003c/h2\u003e\n\u003ch3\u003e2.5.1 场景描述\u003c/h3\u003e\n\u003cblockquote\u003e\n\u003cp\u003e女友不想逛街，又餐厅太吵了，回家好好休息一下。于是我们叫外卖，打个电话点餐，然后我和女友可以在家好好休息一下，饭好了送货员送到家里来。这就是典型的异步，只需要打个电话说一下，然后可以做自己的事情，饭好了就送来了。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch3\u003e2.5.2 网络模型\u003c/h3\u003e\n\u003cp\u003e相对于同步IO，异步IO不是顺序执行。\u003ccode\u003e用户进程进行aio_read系统调用之后，无论内核数据是否准备好，都会直接返回给用户进程，然后用户态进程可以去做别的事情\u003c/code\u003e。等到socket数据准备好了，内核直接复制数据给进程，\u003ccode\u003e然后从内核向进程发送通知\u003c/code\u003e。\u003ccode\u003eIO两个阶段，进程都是非阻塞的\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003eLinux提供了AIO库函数实现异步，但是用的很少。目前有很多开源的异步IO库，例如libevent、libev、libuv。异步过程如下图所示：\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 441px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 62.93%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1176\" data-height=\"740\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-5283bdc9d033e956.png\" data-original-width=\"1176\" data-original-height=\"740\" data-original-format=\"image/png\" data-original-filesize=\"182023\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003ch3\u003e2.5.3 流程描述\u003c/h3\u003e\n\u003cp\u003e用户进程发起aio_read操作之后，立刻就可以开始去做其它的事。而另一方面，从kernel的角度，当它受到一个asynchronous read之后，\u003ccode\u003e首先它会立刻返回，所以不会对用户进程产生任何block\u003c/code\u003e。然后，kernel会等待数据准备完成，然后将数据拷贝到用户内存，\u003ccode\u003e当这一切都完成之后，kernel会给用户进程发送一个signal或执行一个基于线程的回调函数来完成这次 IO 处理过程\u003c/code\u003e，告诉它read操作完成了。\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e在 Linux 中，通知的方式是 “信号”：\u003c/strong\u003e\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e\u003ccode\u003e如果这个进程正在用户态忙着做别的事（例如在计算两个矩阵的乘积），那就强行打断之，调用事先注册的信号处理函数\u003c/code\u003e，这个函数可以决定何时以及如何处理这个异步任务。由于信号处理函数是突然闯进来的，因此跟中断处理程序一样，有很多事情是不能做的，因此保险起见，\u003ccode\u003e一般是把事件 “登记” 一下放进队列，然后返回该进程原来在做的事\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e如果这个进程正在内核态忙着做别的事\u003c/code\u003e，例如以同步阻塞方式读写磁盘，\u003ccode\u003e那就只好把这个通知挂起来了，等到内核态的事情忙完了，快要回到用户态的时候，再触发信号通知\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e如果这个进程现在被挂起了，例如无事可做 sleep 了，那就把这个进程唤醒\u003c/code\u003e，下次有 CPU 空闲的时候，就会调度到这个进程，触发信号通知。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e异步 API 说来轻巧，做来难，这主要是对 API 的实现者而言的。Linux 的异步 IO（AIO）支持是 2.6.22 才引入的，还有很多系统调用不支持异步 IO。Linux 的异步 IO 最初是为数据库设计的，\u003ccode\u003e因此通过异步 IO 的读写操作不会被缓存或缓冲，这就无法利用操作系统的缓存与缓冲机制\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e\u003ccode\u003e很多人把 Linux 的 O_NONBLOCK 认为是异步方式，但事实上这是前面讲的同步非阻塞方式。\u003c/code\u003e\u003c/strong\u003e需要指出的是，虽然 Linux 上的 IO API 略显粗糙，但每种编程框架都有封装好的异步 IO 实现。操作系统少做事，把更多的自由留给用户，正是 UNIX 的设计哲学，也是 Linux 上编程框架百花齐放的一个原因。\u003c/p\u003e\n\u003cp\u003e从前面 IO 模型的分类中，我们可以看出 AIO 的动机：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003e同步阻塞模型需要在 IO 操作开始时阻塞应用程序。这意味着不可能同时重叠进行处理和 IO 操作。\u003c/p\u003e\n\u003cp\u003e同步非阻塞模型允许处理和 IO 操作重叠进行，但是这需要应用程序根据重现的规则来检查 IO 操作的状态。\u003c/p\u003e\n\u003cp\u003e这样就剩下异步非阻塞 IO 了，它允许处理和 IO 操作重叠进行，包括 IO 操作完成的通知。\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eIO多路复用除了需要阻塞之外，\u003ccode\u003eselect 函数所提供的功能（异步阻塞 IO）与 AIO 类似\u003c/code\u003e。不过，\u003ccode\u003e它是对通知事件进行阻塞，而不是对 IO 调用进行阻塞\u003c/code\u003e。\u003c/p\u003e\n\u003ch2\u003e2.6 关于异步阻塞\u003c/h2\u003e\n\u003cp\u003e有时我们的 API 只提供异步通知方式，例如在 node.js 里，\u003ccode\u003e但业务逻辑需要的是做完一件事后做另一件事\u003c/code\u003e，例如数据库连接初始化后才能开始接受用户的 HTTP 请求。\u003ccode\u003e这样的业务逻辑就需要调用者是以阻塞方式来工作\u003c/code\u003e。\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e为了在异步环境里模拟 “顺序执行” 的效果，就需要把同步代码转换成异步形式，这称为 CPS（Continuation Passing Style）变换\u003c/code\u003e。BYVoid 大神的 \u003ca href=\"https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2FBYVoid%2Fcontinuation\" target=\"_blank\"\u003econtinuation.js\u003c/a\u003e 库就是一个 CPS 变换的工具。\u003ccode\u003e用户只需用比较符合人类常理的同步方式书写代码，CPS 变换器会把它转换成层层嵌套的异步回调形式\u003c/code\u003e。\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 684px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 63.22%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1082\" data-height=\"684\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-0d7cf290f0c4b88c.png\" data-original-width=\"1082\" data-original-height=\"684\" data-original-format=\"image/png\" data-original-filesize=\"295152\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 489px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 69.83%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1266\" data-height=\"884\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-199172d7d0ae818d.png\" data-original-width=\"1266\" data-original-height=\"884\" data-original-format=\"image/png\" data-original-filesize=\"385584\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003e另外一种使用阻塞方式的理由是降低响应延迟\u003c/code\u003e。如果采用非阻塞方式，一个任务 A 被提交到后台，就开始做另一件事 B，但 B 还没做完，A 就完成了，这时要想让 A 的完成事件被尽快处理（比如 A 是个紧急事务），要么丢弃做到一半的 B，要么保存 B 的中间状态并切换回 A，任务的切换是需要时间的（不管是从磁盘载入到内存，还是从内存载入到高速缓存），这势必降低 A 的响应速度。\u003ccode\u003e因此，对实时系统或者延迟敏感的事务，有时采用阻塞方式比非阻塞方式更好\u003c/code\u003e。\u003c/p\u003e\n\u003ch1\u003e3 五种IO模型总结\u003c/h1\u003e\n\u003ch2\u003e3.1 blocking和non-blocking区别\u003c/h2\u003e\n\u003cp\u003e调用blocking IO会一直block住对应的进程直到操作完成，而non-blocking IO在kernel还准备数据的情况下会立刻返回。\u003c/p\u003e\n\u003ch2\u003e3.2 synchronous IO和asynchronous IO区别\u003c/h2\u003e\n\u003cp\u003e在说明synchronous IO和asynchronous IO的区别之前，需要先给出两者的定义。POSIX的定义是这样子的：\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eA synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes;\u003c/p\u003e\n\u003cp\u003eAn asynchronous I/O operation does not cause the requesting process to be blocked;\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003ccode\u003e两者的区别就在于synchronous IO做”IO operation”的时候会将process阻塞\u003c/code\u003e。按照这个定义，之前所述的blocking IO，non-blocking IO，IO multiplexing都属于synchronous IO。\u003c/p\u003e\n\u003cp\u003e有人会说，non-blocking IO并没有被block啊。这里有个非常“狡猾”的地方，\u003ccode\u003e定义中所指的”IO operation”是指真实的IO操作\u003c/code\u003e，就是例子中的recvfrom这个system call。non-blocking IO在执行recvfrom这个system call的时候，如果kernel的数据没有准备好，这时候不会block进程。但是，\u003ccode\u003e当kernel中数据准备好的时候，recvfrom会将数据从kernel拷贝到用户内存中，这个时候进程是被block了\u003c/code\u003e，在这段时间内，进程是被block的。\u003c/p\u003e\n\u003cp\u003e而asynchronous IO则不一样，\u003ccode\u003e当进程发起IO 操作之后，就直接返回再也不理睬了，直到kernel发送一个信号，告诉进程说IO完成\u003c/code\u003e。在这整个过程中，进程完全没有被block。\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e各个IO Model的比较如图所示：\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 449px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 64.11%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1276\" data-height=\"818\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-a630f1d47b7ba148.png\" data-original-width=\"1276\" data-original-height=\"818\" data-original-format=\"image/png\" data-original-filesize=\"406467\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e输入图片说明\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e通过上面的图片，可以发现non-blocking IO和asynchronous IO的区别还是很明显的。\u003ccode\u003e在non-blocking IO中，虽然进程大部分时间都不会被block，但是它仍然要求进程去主动的check\u003c/code\u003e，并且当数据准备完成以后，也需要进程主动的再次调用recvfrom来将数据拷贝到用户内存。而asynchronous IO则完全不同。\u003ccode\u003e它就像是用户进程将整个IO操作交给了他人（kernel）完成，然后他人做完后发信号通知\u003c/code\u003e。在此期间，\u003ccode\u003e用户进程不需要去检查IO操作的状态，也不需要主动的去拷贝数据\u003c/code\u003e。\u003c/p\u003e\n\u003cdiv class=\"image-package\"\u003e\n\u003cdiv class=\"image-container\" style=\"max-width: 700px; max-height: 354px;\"\u003e\n\u003cdiv class=\"image-container-fill\" style=\"padding-bottom: 18.34%;\"\u003e\u003c/div\u003e\n\u003cdiv class=\"image-view\" data-width=\"1930\" data-height=\"354\"\u003e\u003cimg data-original-src=\"//upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png\" data-original-width=\"1930\" data-original-height=\"354\" data-original-format=\"image/png\" data-original-filesize=\"281105\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"image-caption\"\u003e个人主页，扫码关注\u003c/div\u003e\n\u003c/div\u003e\n","voted_down":false,"rewardable":true,"show_paid_comment_tips":false,"share_image_url":"https://upload-images.jianshu.io/upload_images/2062729-6c2577a9facdef48.png","slug":"486b0965c296","user":{"liked_by_user":true,"following_count":7872,"gender":1,"avatar_widget":null,"slug":"657c611b2e07","intro":"打蛇打七寸，架构悟认知，亦知海行舟，方悠然自得。","likes_count":13334,"nickname":"七寸知架构","badges":[],"total_fp_amount":"195782395132241559041","wordage":633933,"user_ip_addr":"云南","avatar":"https://upload.jianshu.io/users/upload_avatars/2062729/404b7397-cbe2-40cf-8f36-6c8d019c9788.jpeg","id":2062729,"liked_user":false},"likes_count":445,"paid_type":"free","show_ads":true,"paid_content_accessible":false,"hide_search_input":false,"total_fp_amount":"19733000000000000000","trial_open":false,"reprintable":true,"vip_note":false,"bookmarked":true,"wordage":8006,"featured_comments_count":3,"more_notes":0,"downvotes_count":0,"wangxin_trial_open":null,"guideShow":{"audit_user_nickname_spliter":0,"pc_note_bottom_btn":1,"pc_like_author_guidance":1,"show_more_notes":0,"h5_real_name_auth_link":1,"audit_user_background_image_spliter":0,"audit_note_spliter":0,"new_user_no_ads":1,"audit_post_spliter":0,"pc_login_guidance":1,"audit_comment_spliter":0,"pc_note_bottom_qrcode":1,"audit_user_avatar_spliter":0,"audit_collection_spliter":0,"show_vips_link":1,"pc_top_lottery_guidance":0,"subscription_guide_entry":1,"pdd_ad_percent":0,"explore_score_searcher":0,"matched_split_checker":0,"audit_user_spliter":0,"h5_ab_test":1,"split_checker_percent":0,"home_index_ad":0,"pc_note_popup":2},"commentable":true,"total_rewards_count":5,"id":4008134,"notebook":{"name":""},"activity_collection_slug":null,"description":"上一篇《聊聊同步、异步、阻塞与非阻塞》[https://www.jianshu.com/p/aed6067eeac9]已经通俗的讲解了，要理解同步、异步、阻塞与非阻塞重要的两...","first_shared_at":1463530519,"views_count":139756,"notebook_id":4257867},"baseList":{"likeList":[],"rewardList":[]},"status":"success","statusCode":0},"user":{"isLogin":true,"userInfo":{"id":21216903,"nickname":"DebugYa","slug":"d01b8042d237","avatar":"https://upload.jianshu.io/users/upload_avatars/21216903/76da8667-3674-4427-a757-1ccc99e442a4.jpeg","intro":"","bind_wechat":true,"jsd_level":{"name":"城中平民","level":1},"ads_free":false}},"comments":{"list":[],"featuredList":[]}},"initialProps":{"pageProps":{"query":{"slug":"486b0965c296"}},"localeData":{"common":{"jianshu":"简书","diamond":"简书钻","totalAssets":"总资产{num}","diamondValue":" (约{num}元)","login":"登录","logout":"注销","register":"注册","on":"开","off":"关","follow":"关注","followBook":"关注连载","following":"已关注","cancelFollow":"取消关注","publish":"发布","wordage":"字数","audio":"音频","read":"阅读","reward":"赞赏","zan":"赞","comment":"评论","expand":"展开","prevPage":"上一页","nextPage":"下一页","userIp":"IP属地: {ip}","floor":"楼","confirm":"确定","delete":"删除","report":"举报","fontSong":"宋体","fontBlack":"黑体","chs":"简体","cht":"繁体","jianChat":"简信","postRequest":"投稿请求","likeAndZan":"喜欢和赞","rewardAndPay":"赞赏和付费","home":"我的主页","markedNotes":"收藏的文章","likedNotes":"喜欢的文章","paidThings":"已购内容","wallet":"我的钱包","setting":"设置","feedback":"帮助与反馈","loading":"加载中...","needLogin":"请登录后进行操作","trialing":"文章正在审核中...","reprintTip":"禁止转载，如需转载请通过简信或评论联系作者。"},"error":{"rewardSelf":"无法打赏自己的文章哟~"},"message":{"paidNoteTip":"付费购买后才可以参与评论哦","CommentDisableTip":"作者关闭了评论功能","contentCanNotEmptyTip":"回复内容不能为空","addComment":"评论发布成功","deleteComment":"评论删除成功","likeComment":"评论点赞成功","setReadMode":"阅读模式设置成功","setFontType":"字体设置成功","setLocale":"显示语言设置成功","follow":"关注成功","cancelFollow":"取消关注成功","copySuccess":"复制代码成功"},"header":{"homePage":"首页","download":"下载APP","discover":"发现","message":"消息","reward":"赞赏支持","editNote":"编辑文章","writeNote":"写文章","techarea":"IT技术","vips":"会员"},"note":{},"noteMeta":{"lastModified":"最后编辑于 ","wordage":"字数 {num}","viewsCount":"阅读 {num}","userIp":"IP属地: {ip}","newCopyright":"著作权归作者所有,转载或内容合作请联系作者"},"divider":{"selfText":"以下内容为付费内容，定价 ¥{price}","paidText":"已付费，可查看以下内容","notPaidText":"还有 {percent} 的精彩内容","modify":"点击修改"},"paidPanel":{"buyNote":"支付 ¥{price} 继续阅读","buyBook":"立即拿下 ¥{price}","freeTitle":"该作品为付费连载","freeText":"购买即可永久获取连载内的所有内容，包括将来更新的内容","paidTitle":"还没看够？拿下整部连载！","paidText":"永久获得连载内的所有内容, 包括将来更新的内容","vipLinkTitle":"加入会员,18元/月,畅读全站付费文章"},"book":{"last":"已是最后","lookCatalog":"查看连载目录","header":"文章来自以下连载"},"action":{"like":"{num}人点赞","collection":"收入专题","report":"举报文章"},"comment":{"allComments":"全部评论","featuredComments":"精彩评论","closed":"评论已关闭","close":"关闭评论","open":"打开评论","desc":"按时间倒序","asc":"按时间正序","disableText1":"用户已关闭评论，","disableText2":"与Ta简信交流","placeholder":"写下你的评论...","publish":"发表","create":" 添加新评论","reply":" 回复","restComments":"还有{num}条评论，","expandImage":"展开剩余{num}张图","deleteText":"确定要删除评论么？"},"collection":{"title":"被以下专题收入，发现更多相似内容","putToMyCollection":"收入我的专题"},"seoList":{"title":"推荐阅读","more":"更多精彩内容"},"sideList":{"title":"推荐阅读"},"wxShareModal":{"desc":"打开微信“扫一扫”，打开网页后点击屏幕右上角分享按钮"},"bookChapterModal":{"try":"试读","toggle":"切换顺序"},"collectionModal":{"title":"收入到我管理的专题","search":"搜索我管理的专题","newCollection":"新建专题","create":"创建","nothingFound":"未找到相关专题","loadMore":"展开查看更多"},"contributeModal":{"search":"搜索专题投稿","newCollection":"新建专题","addNewOne":"去新建一个","nothingFound":"未找到相关专题","loadMore":"展开查看更多","managed":"我管理的专题","recommend":"推荐专题"},"QRCodeShow":{"payTitle":"微信扫码支付","payAfbTitle":"支付宝扫码支付","payText":"支付金额"},"rewardModal":{"title":"给作者送糖","custom":"自定义","placeholder":"给Ta留言...","choose":"选择支付方式","balance":"简书余额","tooltip":"网站该功能暂时下线，如需使用，请到简书App操作","confirm":"确认支付","success":"赞赏成功"},"payModal":{"payBook":"购买连载","payNote":"购买文章","promotion":"优惠券","promotionFetching":"优惠券获取中...","noPromotion":"无可用优惠券","promotionNum":"{num}张可用","noUsePromotion":"不使用优惠券","validPromotion":"可用优惠券","invalidPromotion":"不可用优惠券","total":"支付总额","tip1":"· 你将购买的商品为虚拟内容服务，购买后不支持退订、转让、退换，请斟酌确认。","tip2":"· 购买后可在“已购内容”中查看和使用。","success":"购买成功"},"reportModal":{"abuse":"辱骂、人身攻击等不友善内容","minors_forbidden":"未成年违规内容","ad":"广告及垃圾信息","plagiarism":"抄袭或未授权转载","placeholder":"写下举报的详情情况（选填）","it_algorithm_rec":"涉互联网算法推荐","it_violence":"涉网络暴力有害信息","success":"举报成功"},"guidModal":{"modalAText":"相似文章推荐","subText":"下载简书APP，浏览更多相似文章","btnAText":"先不下载，下次再说","followOkText":"关注作者成功！","followTextTip":"下载简书APP，作者更多精彩内容更新及时提醒！","followBtn":"下次再说","downloadTipText":"更多精彩内容，就在简书APP","footerDownLoadText":"下载简书APP","modabTitle":"免费送你2次抽奖机会","modalbTip":"抽取10000收益加成卡，下载简书APP概率翻倍","modalbFooterTip":"下载简书APP，天天参与抽大奖","modalReward":"抽奖","scanQrtip":"扫码下载简书APP","downloadAppText":"下载简书APP，随时随地发现和创作内容","redText":"阅读","likesText":"赞","downLoadLeft":"手机看全文","leftscanText":"把文字装进口袋"}},"currentLocale":"zh-CN","asPath":"/p/486b0965c296"}},"page":"/p/[slug]","query":{"slug":"486b0965c296"},"buildId":"ktM9fpG1ne1VL7zVgTq0a","assetPrefix":"https://cdn2.jianshu.io/shakespeare"}</script><script nomodule="" src="聊聊Linux%20五种IO模型%20-%20简书_files/polyfills-83c9f0eea3aa0edfd89e.js.下载"></script><script async="" data-next-page="/p/[slug]" src="聊聊Linux%20五种IO模型%20-%20简书_files/%5Bslug%5D.js.下载"></script><script async="" data-next-page="/_app" src="聊聊Linux%20五种IO模型%20-%20简书_files/_app.js.下载"></script><script src="聊聊Linux%20五种IO模型%20-%20简书_files/webpack-b1da0f857c45af7b8400.js.下载" async=""></script><script src="聊聊Linux%20五种IO模型%20-%20简书_files/commons.a44ef645208dcbc051d0.js.下载" async=""></script><script src="聊聊Linux%20五种IO模型%20-%20简书_files/styles.d2e8d5d9794ce93096fa.js.下载" async=""></script><script src="聊聊Linux%20五种IO模型%20-%20简书_files/main-bf58e64b3bbaeed6553f.js.下载" async=""></script><div><template shadowrootmode="closed"><link rel="stylesheet" href="chrome-extension://ghgabhipcejejjmhhchfonmamedcbeod/fcss41/ebtn41.css"><svg width="16px" height="16px" hide=""><path id="__path" d="M16 14V2a2 2 0 00-2-2H2a2 2 0 00-2 2v12c0 1.1.9 2 2 2h12a2 2 0 002-2z"></path><path fill="#f9f6e8" d="M12.9 12.2c.2-.2.3-.5.3-.8 0-.6-.5-1.2-1.2-1.2-.3 0-.6.1-.9.4-.7.7-1.7 1-2.6 1-2 0-3.8-1.6-3.8-3.6s1.7-3.6 3.8-3.6c1 0 2 .3 2.6 1 .3.3.6.4.9.4.7 0 1.3-.5 1.3-1.2 0-.3-.2-.6-.4-.8A6.4 6.4 0 008.5 2a6.1 6.1 0 00-6.3 6c0 3.3 2.8 6 6.3 6 1.6 0 3.2-.6 4.4-1.8z"></path></svg></template></div><div><div><div class="_23ISFX-mask _23ISFX-mask-hidden"></div><div tabindex="-1" class="_23ISFX-wrap _23ISFX-wrap-middle" role="dialog" style="display: none;"><div role="document" class="_23ISFX" style="width: 640px;"><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div><div class="_23ISFX-content"><button type="button" aria-label="Close" class="_23ISFX-close"><div class="_23ISFX-close-x"><i aria-label="icon: close" class="anticon anticon-close"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></div></button><div class="_23ISFX-body"><div class="_2MkxS4"><div class="_2Q0eC2">扫码安装简书客户端</div><div class="_2Q0eC2">畅享全文阅读体验</div><img src="./聊聊Linux 五种IO模型 - 简书_files/js-qrc.png" class="_2Sn0OY"><div class="_2Q0eC2">扫码后在手机中选择通过第三方浏览器下载</div></div></div></div><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div></div></div></div></div><div style="position: absolute; top: 0px; left: 0px; width: 100%;"><div><div class="ant-dropdown  ant-dropdown-placement-bottomLeft  ant-dropdown-hidden" style="left: 1002.08px; top: 5103.2px;"><ul class="ant-dropdown-menu _359BF5 ant-dropdown-menu-light ant-dropdown-menu-root ant-dropdown-menu-vertical" role="menu" tabindex="0"><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/u/d01b8042d237" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_mine" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_mine"></use></svg></i><span>我的主页</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/bookmarks" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_collection" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_collection"></use></svg></i><span>收藏的文章</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/users/d01b8042d237/liked_notes" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_like" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_like"></use></svg></i><span>喜欢的文章</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/my/paid_notes" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_purchased" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_purchased"></use></svg></i><span>已购内容</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/wallet" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_wallet" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_wallet"></use></svg></i><span>我的钱包</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/settings" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_setting" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_setting"></use></svg></i><span>设置</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><a class="_4yOlTc _1OhGeD" href="https://www.jianshu.com/faqs" target="_blank" rel="noopener noreferrer"><i aria-label="ic-icon_help" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_help"></use></svg></i><span>帮助与反馈</span></a></li><li class="ant-dropdown-menu-item _36elk0" role="menuitem"><div class="_4yOlTc"><i aria-label="ic-icon_logout" class="anticon _32Ne73"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-icon_logout"></use></svg></i><span>退出</span></div></li></ul></div></div></div></body></html>